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 decorate bug (#4277) without adding extra layers of render tree #4421

Merged
merged 3 commits into from
Aug 10, 2021

Conversation

jaked
Copy link
Contributor

@jaked jaked commented Aug 7, 2021

Description
The combination of #4152 and #4138 broke decoration in Editable: the decorate function is not called on immediate children of the editor (because the function is retrieved from a React context before the context is set).

I fixed this in #4394 by adding a wrapper component around each child in useChildren, so the context is set by the time we retrieve the decorate function.

But after some discussion with @ulion (on #4277 and #4394) I think it's better not to wrap every child, but only the immediate children of Editable; this achieves the same thing without adding extra layers to the render tree. And since the immediate children of Editable are not passed to renderLeaf, it's not necessary to wrap them individually for #4152. So this change reverts the changes to use-children.tsx from #4394, and adds back a Children component in Editable in order to defer the call to useDecorate.

Issue
Fixes: #4277

Example
See test—decorate is called on all children of editor.

Context
As above, the issue is that a React context (added in #4138) is used before being set (because #4152 replaced the Children component with a call to useChildren). In order to fix the bug without defeating the goals of these two changes, we wrap a Children component around the useChildren call in Editable to defer the use of the context.

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.) No changeset needed; no functionality is affected by this change.

@changeset-bot
Copy link

changeset-bot bot commented Aug 7, 2021

🦋 Changeset detected

Latest commit: 6aaf329

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

This PR includes changesets to release 2 packages
Name Type
slate-react Patch
slate 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
Copy link
Collaborator

dylans commented Aug 9, 2021

thanks, I thought a changeset was not needed because no functionality was changed.

My opinion is that something did change which makes it easier to track down regressions, but I could argue it either way. :)

@dylans dylans merged commit 237edc6 into ianstormtaylor:main Aug 10, 2021
This was referenced Aug 10, 2021
dylans added a commit to dylans/slate that referenced this pull request Sep 13, 2021
… render tree (ianstormtaylor#4421)

* fix ianstormtaylor#4394 without adding extra layers of render tree

* oops unused import

* Add changeset

Co-authored-by: Dylan Schiemann <dylan@dojotoolkit.org>
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.

useDecorate return default method,not the override in custom in some case
2 participants