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

Add flushSync option to update() #3119

Merged
merged 2 commits into from
Oct 17, 2022
Merged

Add flushSync option to update() #3119

merged 2 commits into from
Oct 17, 2022

Conversation

fantactuka
Copy link
Contributor

This would allow synchronous updates (e.g. for tests and some cases of headless mode):

editor.update(() => {
  ...
}, { flushSync: true });

// Update and listeners are already executed

@trueadm
Copy link
Collaborator

trueadm commented Oct 5, 2022

I don't think we want to call it flushSync as this would encourage people to always use it. discrete would be more accurate and follow the terminology browsers and React uses for the same behaviors.

@fantactuka
Copy link
Contributor Author

discrete

Thought react uses flushSync, but discrete sounds good too

@fantactuka
Copy link
Contributor Author

@trueadm Another option I had in mind is to add $flushSync() util to be called within updateFn. It might make it even more explicit than a flag

@trueadm
Copy link
Collaborator

trueadm commented Oct 5, 2022

Thought react uses flushSync, but discrete sounds good too

That's true, I guess I meant as the underlying terminology. I'm just worried everyone will do this rather than use async updates.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 5, 2022
@vercel
Copy link

vercel bot commented Oct 5, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
lexical ✅ Ready (Inspect) Visit Preview Oct 17, 2022 at 2:40AM (UTC)
lexical-playground ✅ Ready (Inspect) Visit Preview Oct 17, 2022 at 2:40AM (UTC)

@trueadm
Copy link
Collaborator

trueadm commented Oct 5, 2022

Another option I had in mind is to add $flushSync() util to be called within updateFn. It might make it even more explicit than a flag

Gets complicated with nested updates though and what should happen when others happen etc.

@fantactuka
Copy link
Contributor Author

fantactuka commented Oct 5, 2022

Another alternative would be to have it in a headless mode as a default (so far it's the main usecase), since there's no benefit from batching as there's no dom reconciliation. Then can just rely on _headless flag. Although it adds implicit inconsistency between .update calls & updated state availability right after it

@acywatson
Copy link
Contributor

That's true, I guess I meant as the underlying terminology. I'm just worried everyone will do this rather than use async updates.

Would this really be a problem? You'd have to go looking for this API and then maybe we could ameliorate the problem with some documentation around valid use cases for it.

@trueadm
Copy link
Collaborator

trueadm commented Oct 5, 2022

Lexical used to have a flush sync flag, we actually killed it. Everyone used that in their tests and then their production surfaces were in async causing a different behavior.

@fantactuka
Copy link
Contributor Author

Lexical used to have a flush sync flag, we actually killed it. Everyone used that in their tests and then their production surfaces were in async causing a different behavior.

With that I don't like neither of solutions anymore :) But using internal _flushSync flag is even more confusing, so I'll move on with discrete

@acywatson acywatson merged commit 0dd855a into main Oct 17, 2022
acywatson pushed a commit that referenced this pull request Oct 18, 2022
* Add flushSync option to update()

* Rename flushSync->discrete
thegreatercurve pushed a commit that referenced this pull request Nov 25, 2022
* Add flushSync option to update()

* Rename flushSync->discrete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants