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

Regression in ReactEditor.focus since 0.101.0 #5568

Open
philicious opened this issue Nov 27, 2023 · 2 comments
Open

Regression in ReactEditor.focus since 0.101.0 #5568

philicious opened this issue Nov 27, 2023 · 2 comments
Labels

Comments

@philicious
Copy link

philicious commented Nov 27, 2023

Description
slate-react 0.101.0 reverted #5542 but must have introduced yet another problem as we still face a problem with ReactEditor.focus, so might be a problem introduced by #5527

Steps

  useEffect(() => {
    editor.children = value
    editor.onChange()

    ReactEditor.focus(editor) // this line now causes the editor to blank out!! if removed, its working but editor doesnt get initial focus
  }, [value, editor])
...
    <Slate
      editor={editor}
      initialValue={[]}
    >

Expectation
ReactEditor.focus works as before, i.e. I can focus editor and it doesnt blank out

Environment

  • Slate-react 0.101.0 and onwards
@philicious philicious added the bug label Nov 27, 2023
@philicious philicious changed the title Regression since 0.101.0 Regression in ReactEditor.focus since 0.101.0 Nov 27, 2023
@skogsmaskin
Copy link
Collaborator

skogsmaskin commented Nov 28, 2023

Hi! I'm unable to reproduce this and determine if this is a regression caused by #5527.

The following test passes:

   test('can call ReactEditor.focus in hook', async () => {
     const editor = withReact(createEditor())
     const initialValue = [{ type: 'block', children: [{ text: 'test' }] }]
     const loadedValue = [{ type: 'block', children: [{ text: 'another test' }] } as Descendant]

     const TestComponent = () => {
       useEffect(() => {
         editor.children = loadedValue
         editor.onChange()
         ReactEditor.focus(editor)
       }, [])
       return (
         <Slate editor={editor} initialValue={initialValue}>
           <Editable />
         </Slate>
       )
     }

     await act(async () => {
       render(<TestComponent />)
     })

     expect(editor.selection).toEqual({"anchor": {"offset": 0, "path": [0, 0]}, "focus": {"offset": 0, "path": [0, 0]}})
     expect(editor.children).toEqual(loadedValue)
   })
 })

Also, similar code modifying the plaintext example also works fine here in a real browser (Chrome on MacOS).

@philicious
Copy link
Author

Thx @skogsmaskin for testing.
I'll do more testing myself to pin down the problem.

However, We started seeing this problem with release of #5542 but that should be reverted in 0.101.0

Major difference I see in your test is that you have an initial value set while we have an empty one

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

2 participants