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

feat(runtime-core): check if the key is string #1731

Merged
merged 1 commit into from
Jul 29, 2020

Conversation

pikax
Copy link
Member

@pikax pikax commented Jul 29, 2020

On the rc.5 I started getting errors because a symbol was used during render, because indexOf is not available on symbol.

This test is not representative on you will get this problem, but rather a way to trigger it.

The "errors" can be found CI build here (the first error is not related to this particular case) but exception is not being bubble up

after manually disabling the recursive vue-next log error:

    TypeError: key.indexOf is not a function

      at Object.get (node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5422:17)
      at Proxy.render (eval at compileToFunction (packages/vue-composable/__tests__/utils.ts:85:18), <anonymous>:12:13)
      at renderComponentRoot (node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:481:44)
      at componentEffect (node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:4040:53)
      at reactiveEffect (node_modules/@vue/reactivity/dist/reactivity.cjs.js:46:24)
      at Object.effect (node_modules/@vue/reactivity/dist/reactivity.cjs.js:21:9)
      at setupRenderEffect (node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:4032:38)
      at mountComponent (node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3990:9)
      at processComponent (node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3947:17)
      at patch (node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3607:21)
      at render (node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:4675:13)
      at mount (node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3106:25)
      at Object.app.mount (node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.js:1197:23)
      at Object.mount (packages/vue-composable/__tests__/utils.ts:115:16)
      at Object.<anonymous> (packages/vue-composable/__tests__/misc/vmodel.spec.ts:87:8)

Code causing the issue

// composable
export function useVModel<TProps, PropName extends keyof TProps>(
  props: TProps,
  name: PropName
): Ref<TProps[PropName]>;
export function useVModel(props: Record<string, any>, name: string): Ref<any> {
  const instance = getCurrentInstance();
  if (!instance) {
    return ref() as any;
  }
  return computed({
    get() {
      return props[name];
    },
    set(v) {
      instance.emit(`update:${name}`, v);
    }
  });
}


// test using the composable , just checking if parent does get the actual update when using `test.value ='mounted'`

it("should replace prop", async () => {
    const comp1 = {
      props: {
        test: String
      },
      setup(props: { test: string }) {
        const test = useVModel(props, "test");

        onMounted(() => {
          test.value = "mounted";
        });

        return {
          test
        };
      },
      template: `<p>{{test}}</p>`
    };

    const test = ref("propTest");

    const vm = createVue({
      components: {
        comp1
      },
      template: `<comp1 v-model:test="test" />`,
      setup() {
        return {
          test
        };
      }
    });

    expect(test.value).toBe("propTest");
    vm.mount();
    await nextTick();

    expect(test.value).toBe("mounted");
  });

@yyx990803 yyx990803 merged commit ce78eac into vuejs:master Jul 29, 2020
@pikax pikax deleted the feat/prevent_error_on_render branch August 22, 2020 09:03
@rhengles
Copy link

Why do we want that opaque Property undefined was accessed during render but is not defined on instance. ?

I'm sure that that causes many people to be scratching their heads, just like I did!

It would be better if on runtime-core/componentPublicInstance.ts, on the function PublicInstanceProxyHandlers.get(), if the key is Symbol.unscopables, it would silently return undefined instead of printing that warning that is not the fault of the user!

Related: #2910

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.

4 participants