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

fix: Add missing dependencies to useEffect and React.memo calls (#5289) #5310

Merged
merged 2 commits into from
Feb 23, 2023

Conversation

etrepum
Copy link
Contributor

@etrepum etrepum commented Feb 23, 2023

Description
The merge of #5261 caused a regression where the first value of onChange is cached indefinitely because it is not used as a dependency of the effect that is supposed to maintain it. This fixes that bug, and similar bugs in the React.memo comparisons for MemoizedElement and MemoizedText where a cached renderPlaceholder is passed down to the leaf.

Issue
Fixes: #5289

Example
See the recording in #5289 for an example of the bug. A similar one could be crafted with renderPlaceholder being cached if necessary, but it should be pretty clear from the code.

Context
There aren't really other ways to fix these issues in a localized manner. I did look into adding the eslint plugin that can help check hook dependencies but there are violations in the code that would require distracting workarounds or API changes so I opted to keep it concise.

Checks

  • The new code matches the existing patterns and styles.
  • The tests pass with yarn test.
  • The linter passes with yarn lint. (Fix errors with yarn fix.)
  • The relevant examples still work. (Run examples with yarn start.)
  • You've added a changeset if changing functionality. (Add one with yarn changeset add.)

@changeset-bot
Copy link

changeset-bot bot commented Feb 23, 2023

🦋 Changeset detected

Latest commit: 386b437

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
slate-react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dylans dylans merged commit b94254d into ianstormtaylor:main Feb 23, 2023
@github-actions github-actions bot mentioned this pull request Feb 23, 2023
@etrepum etrepum deleted the fix-5289-onChange branch February 23, 2023 20:27
@kaya-altin
Copy link

Hello, after then this version, there is a problem of not being able to focus on the first click. I think it's related to the placeholder, the issue doesn't occur when the placeholder is removed. @etrepum

Screen.Recording.2023-03-03.at.10.11.41.mov

@etrepum
Copy link
Contributor Author

etrepum commented Mar 3, 2023

@kaya-altin the only thing this PR can do is cause components to render more often. I think you are seeing a bug related to one of the other changes that were merged since the last version you tested.

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

Successfully merging this pull request may close these issues.

slate-react doesn't use most up-to-date onChange callback
3 participants