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

[Bug]: can't access ref on EditorContent in react #4470

Closed
1 of 2 tasks
sereneinserenade opened this issue Sep 24, 2023 · 6 comments
Closed
1 of 2 tasks

[Bug]: can't access ref on EditorContent in react #4470

sereneinserenade opened this issue Sep 24, 2023 · 6 comments
Assignees
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug

Comments

@sereneinserenade
Copy link
Contributor

sereneinserenade commented Sep 24, 2023

Which packages did you experience the bug in?

react

What Tiptap version are you using?

2.1.11

What’s the bug you are facing?

<EditorContent editor={editor} ref={editorContentRef} />

I want to access ref on EditorContent but it's not working.

What browser are you using?

Chrome

Code example

<EditorContent editor={editor} ref={editorContentRef} />

What did you expect to happen?

I should be able to access EditorContent's internal state and other things via ref.

Anything to add? (optional)

fix is in #4471

instead of

const EditorContentWithKey = (props: EditorContentProps) => {
  const key = React.useMemo(() => {
    return Math.floor(Math.random() * 0xFFFFFFFF).toString()
  }, [props.editor])

  // Can't use JSX here because it conflicts with the type definition of Vue's JSX, so use createElement
  return React.createElement(PureEditorContent, { key, ...props })
}

we can do

const EditorContentWithKey = React.forwardRef((props: EditorContentProps, ref: React.RefObject<any>) => {
  const key = React.useMemo(() => {
    return Math.floor(Math.random() * 0xFFFFFFFF).toString()
  }, [props.editor])

  // Can't use JSX here because it conflicts with the type definition of Vue's JSX, so use createElement
  return React.createElement(PureEditorContent, { key, ref, ...props })
})

Did you update your dependencies?

  • Yes, I’ve updated my dependencies to use the latest version of all packages.

Are you sponsoring us?

  • Yes, I’m a sponsor. 💖
@sereneinserenade sereneinserenade added Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug labels Sep 24, 2023
@github-project-automation github-project-automation bot moved this to Triage open in Tiptap Sep 24, 2023
@ioma8
Copy link

ioma8 commented Nov 14, 2023

I wish this to be fixed.

@Nantris
Copy link
Contributor

Nantris commented Nov 15, 2023

Related to #4632.

Both occur because the props aren't passed through at all.

Actually this one appears to be because it uses a ref internally already. To fix this refs need to be merged here:

render() {
const { editor, ...rest } = this.props
return (
<>
<div ref={this.editorContentRef} {...rest} />
{/* @ts-ignore */}
<Portals renderers={this.state.renderers} />
</>
)
}
}

@ehynds
Copy link
Contributor

ehynds commented Dec 28, 2023

I opened #4396 a while back to fix this. Can this be reviewed and merged?

@HRSAndrabi
Copy link

HRSAndrabi commented Jan 1, 2024

Also hoping to see #4396 implemented.

@bdbch
Copy link
Member

bdbch commented Jan 2, 2024

I just merged #4396 and will probably release a new release candidate today so you could test this behavior the next days if you switch to the most recent RC version

@nperez0111
Copy link

Resolved with #4396

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug
Projects
No open projects
Archived in project
Development

No branches or pull requests

9 participants