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

Skip wrapping nodes when the only match is an editor #4253

Merged
merged 2 commits into from
Aug 5, 2021

Conversation

TheSpyder
Copy link
Collaborator

Description
Transforms.wrapNodes attempts to detect when zero nodes match, but it missed an edge case where one node matches - the editor. The function very quickly throws Error: Cannot get the parent path of the root path [] when this happens.

Example
The test shows the failure condition. The editor I'm working on supports contenteditable=false sections in document content, and while we are able to handle most of the filtering outside of slate this is one case that is difficult to handle without a lot of extra code.

Context
There are a few other ways I can think of to fix this - such as wrapping the supplied match function to enforce !Editor.isEditor - but this seemed like the least invasive way to deal with it.

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 May 10, 2021

🦋 Changeset detected

Latest commit: dfbd20e

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

This PR includes changesets to release 1 package
Name Type
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

packages/slate/src/transforms/node.ts Outdated Show resolved Hide resolved
@dylans dylans merged commit 0214b63 into ianstormtaylor:main Aug 5, 2021
@TheSpyder TheSpyder deleted the wrapnodes-no-match branch August 9, 2021 05:06
dylans pushed a commit to dylans/slate that referenced this pull request Sep 13, 2021
…4253)

* Skip wrapping nodes when the only match is an editor

* Check for empty path instead of using isEditor
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.

None yet

3 participants