Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setValue has no effect #1169

Closed
rgrzywinski opened this issue Oct 24, 2021 · 7 comments
Closed

setValue has no effect #1169

rgrzywinski opened this issue Oct 24, 2021 · 7 comments
Labels
bug Something isn't working slate

Comments

@rgrzywinski
Copy link

rgrzywinski commented Oct 24, 2021

Description

To clear the editor (or set to some initial value) it has been documented to use the value property on Plate (e.g. via a useState hook). I simply cannot get a recent version of Plate to respond to either setValue (in the store) or via the value prop.

Steps

I have forked a CodeSandbox from another issue where clearing the editor worked as expected and updated it with the latest Plate dependencies: https://codesandbox.io/s/plate-onkeydown-error-forked-945d9?file=/src/App.js

(Simply follow the instructions in the browser.)

Sandbox

https://codesandbox.io/s/plate-onkeydown-error-forked-945d9?file=/src/App.js

Expectation

value (or usePlateActions's setValue()) will cause the value of the editor to change.

Environment

  • slate: 6.1.0
  • slate-react: 0.67.0
  • browser: chrome
@rgrzywinski rgrzywinski added the bug Something isn't working label Oct 24, 2021
@dylans
Copy link
Collaborator

dylans commented Oct 24, 2021

My guess is ianstormtaylor/slate#4540 caused a regression here when using Slate 0.67.0 and newer.

@rgrzywinski
Copy link
Author

rgrzywinski commented Oct 24, 2021

FYI -- you can force children to the desired value (with no apparent ill effects):

    const editor = useStoreEditorState(id);

....

    const point = { path: [0, 0], offset: 0 };
    editor!.selection = { anchor: point, focus: point };
    editor!.history = { redos: [], undos: [] };
    editor!.children = <desired value>;

@rgrzywinski
Copy link
Author

(From ianstormtaylor/slate#3575 it seems like setting children is the preferred / correct approach now... ?)

@zbeyens zbeyens added the slate label Oct 24, 2021
@GhostsCode
Copy link

FYI -- you can force children to the desired value (with no apparent ill effects):

    const editor = useStoreEditorState(id);

....

    const point = { path: [0, 0], offset: 0 };
    editor!.selection = { anchor: point, focus: point };
    editor!.history = { redos: [], undos: [] };
    editor!.children = <desired value>;

I'm a newbie and I've applied this code. In my situation, it keeps on re-rendering the component. So, what happens is that everytime I type, the focus is always at 0,0. Am I missing something here?

@rgrzywinski
Copy link
Author

I also had a "re-render on every keypress" problem but after memo'izing my editableProps it no longer occurred.

BTW -- that code is for how to clear the editor (e.g. if you wanted to do a 'reset') so if you've applied it directly within a "set value" situation then of course it's going to re-render and set the cursor to (0,0) (since that's what it does!).

@GhostsCode
Copy link

I see, thank you for your reply.

@zbeyens
Copy link
Member

zbeyens commented Nov 2, 2021

@zbeyens zbeyens closed this as completed Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working slate
Projects
None yet
Development

No branches or pull requests

4 participants