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

Prop validation uses StringTag, which invalidates valid props #1872

Closed
SebastianSpeitel opened this issue Aug 17, 2020 · 0 comments
Closed

Comments

@SebastianSpeitel
Copy link

Version

3.0.0-rc.5

Reproduction link

https://github.com/SebastianSpeitel/vue-bug-stringtag

Steps to reproduce

Build and run Vue App.
Then look in the console.

// App.vue
<template>
  <div>
    <Comp :obj="obj" :obj2="obj" :obj3="obj" />
  </div>
</template>

<script>
import Comp from "./components/Component.vue";

export default {
  components: {
    Comp
  },
  setup() {
    const obj = {
      get [Symbol.toStringTag]() {
        return "NotObject";
      }
    };

    return { obj };
  }
};
</script>
// components/Component.vue
<template>
  <div />
</template>

<script>
export default {
  name: "HelloWorld",
  props: {
    obj: Object,
    obj2: { type: Object },
    obj3: { validator: o => typeof o === "object" }
  }
};
</script>

image

What is expected?

An Object with an overridden Symbol.toStringTag getter should be a valid prop for type:Object

What is actually happening?

The type assertion uses the StringTag to compare the type of objects when the prop type is the Object constructor.


For type assertion of objects in assertType [2], toRawType [3] is used, where it would be more intuitive to just use typeof prop === 'object' && prop !== null.

[2]:

https://github.com/vuejs/vue-next/blob/304830a764cd9f28098cfb0ac0e520e1bb2f57c7/packages/runtime-core/src/componentProps.ts#L489-L510

[3]:

https://github.com/vuejs/vue-next/blob/304830a764cd9f28098cfb0ac0e520e1bb2f57c7/packages/shared/src/index.ts#L76-L78

@github-actions github-actions bot locked and limited conversation to collaborators Nov 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant