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

VueRenderer's ref is undefined when in production mode #1271

Merged
merged 1 commit into from
May 5, 2021

Conversation

thechrisoshow
Copy link
Sponsor Contributor

@thechrisoshow thechrisoshow commented May 5, 2021

I created a version of the Mention extension, heavily based on the example code when I noticed an issue, the keydown handler didn't work.

(Sample repo of the code not working: https://github.com/thechrisoshow/tiptap-mentions
Running at: https://determined-minsky-6136aa.netlify.app/ )

This was because of how we're sending messages from the parent component to the child using the VueRenderer's ref.

e.g.

onKeyDown(props) {
  // this fails with error on production like:
  // "Uncaught TypeError: Cannot read property '3573854894' of undefined"
  return component.ref?.onKeyDown(props);
},

It would work perfectly on development, but it looks like on production the underlying ctx object has the $refs stripped away, so the following wouldn't work (from VueRenderer.ts)

  get ref(): any {
    // On production, ctx no longer has a $refs object
    return this.editor.contentComponent?.ctx.$refs[this.id]
  }

I noticed though that ComponentInternalInstance has a refs object, so we can fix this problem by using this instead:

  get ref(): any {
    // Works on both production and development
    return this.editor.contentComponent?.refs[this.id]
  }

@hanspagel hanspagel added the sponsor 💖 This issue or pull request was created by a Tiptap sponsor label May 5, 2021
@philippkuehn philippkuehn merged commit 4fa75d8 into ueberdosis:main May 5, 2021
@philippkuehn
Copy link
Contributor

oh great, thank you! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sponsor 💖 This issue or pull request was created by a Tiptap sponsor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants