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

[packages/vue-2]: Avoid mutating a prop directly error message #2833

Closed
1 of 2 tasks
HondryTravis opened this issue May 30, 2022 · 1 comment
Closed
1 of 2 tasks

[packages/vue-2]: Avoid mutating a prop directly error message #2833

HondryTravis opened this issue May 30, 2022 · 1 comment
Labels
Type: Bug The issue or pullrequest is related to a bug

Comments

@HondryTravis
Copy link
Contributor

What’s the bug you are facing?

vue.esm.js:628 [Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. 
Instead, use a data or computed property based on the prop's value. Prop being mutated: "selected"

Which browser was this experienced in? Are any special extensions installed?

browser: mac chrome 102.0.5005.61 (x86_64)
special extensions installed: No

How can we reproduce the bug on our side?

just useing nodeview will tirgger this error;

// ...
import { VueNodeViewRenderer } from '@tiptap/vue-2'

// ...
const other = extension.extend({
   addNodeView(){
      return VueNodeViewRenderer(somethingView);
   }
})

just refresh browser will see this error

Can you provide a CodeSandbox?

No response

What did you expect to happen?

this error message is who changes vue-2/src/VueNodeViewRenderer.ts:89

// @ts-ignore
const vue = this.editor.contentComponent?.$options._base ?? Vue // eslint-disable-line

vue-2/src/VueRenderer.ts:17:invalidate Vue.config.silent configuration in updateProps method,it's not work. Vue constructor is different

updateProps(props: Record<string, any> = {}): void {
  if (!this.ref.$props) {
    return
  }

  // prevents `Avoid mutating a prop directly` error message
  // here
  const originalSilent = Vue.config.silent

  Vue.config.silent = true

  Object
    .entries(props)
    .forEach(([key, value]) => {
      this.ref.$props[key] = value
    })

  Vue.config.silent = originalSilent
}

this is fixed methods

fixed:

it's working vue2

updateProps(props: Record<string, any> = {}): void {
  if (!this.ref.$props) {
    return
  }

  // prevents `Avoid mutating a prop directly` error message
  // const originalSilent = Vue.config.silent
  const currentVue = this.ref.$props.editor.contentComponent?.$options._base ?? Vue;
  const originalSilent = currentVue.config.silent
  currentVue.config.silent = true

  Object
    .entries(props)
    .forEach(([key, value]) => {
      this.ref.$props[key] = value
    })

  currentVue.config.silent = originalSilent
}

I hope fixed this error;

Anything to add? (optional)

No response

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. 💖
@HondryTravis HondryTravis added the Type: Bug The issue or pullrequest is related to a bug label May 30, 2022
@HondryTravis
Copy link
Contributor Author

For more info pls see pull requests 2834

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug The issue or pullrequest is related to a bug
Projects
None yet
Development

No branches or pull requests

1 participant