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

make slate a controlled input #5281

Open
macrozone opened this issue Feb 2, 2023 · 2 comments
Open

make slate a controlled input #5281

macrozone opened this issue Feb 2, 2023 · 2 comments
Labels

Comments

@macrozone
Copy link
Contributor

Problem

Slate was recently changed to be an uncontrolled component. this leads to massive problems for integrators of slate as uncontrolled components are not predictable because they have an inner state that is not fully controllable from outside.

Uncontrolled components therefore lead to bugs and inconsistencies

Solution

Slate should be a controlled component, means that it will always show consistently what is passed as a value

Alternatives

a workaround is shown here #4992 but that also does not always work. Since it relies on a useEffect the execution of the effect might be delayed and things get out of sync.

Context
I am maintaining https://github.com/react-page/react-page and we use slate for rich-text editing. Since the mentioned update we have a hard time to fix all inconsistencies regarding slate

@aboveyunhai
Copy link

Uncontrolled component itself its fine, the problem is that the person with knowledge who made those breaking changes, failed to include the uncontrolled doc for those changes, and neglect the controlled behavior in React. It starts to turn out to be a mess now.

One thing I am pretty sure is that if you are using useEffect to update the state without waiting something externally from outside of the app (like waiting for an api call and then update the internal data). You might be doing something wrong most of the times.

I believe the "intended" way based on the PR is to directly call those Transforms.XXX, Editor.apply, etc. to do the state(editor value) manipulation. You have to simplify, wrap those inner functions and expose to the users if you want to let user control the value since slate-react currently failed to provide some shortcut helper functions for this part.

@erano067
Copy link

Any update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants