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

fix(runtime-core): catch TypeError when setting invalid props #1051

Closed
wants to merge 1 commit into from

Conversation

pikax
Copy link
Member

@pikax pikax commented Apr 25, 2020

Fix the case when the html element has type validation for a specific prop.

<template>
  <button @click="toggle">Press me {{srcObject}}</button>
  <video :srcObject="srcObject" />
</template>

<script>
import { ref } from "vue";
export default {
  setup() {
    const srcObject = ref(0);
    const toggle = () => srcObject.value++;
    return { srcObject, toggle };
  }
};
</script>

@jonaskuske
Copy link
Contributor

jonaskuske commented Apr 26, 2020

I don't think that wrapping this in a try/catch is enough to solve this. :/
As we're still casting to "" instead of actually setting the property to null when it is required, in the following example stopping the video won't work since the browser will just ignore our attempt to set srcObject to "" and keep playing back the video with the previous srcObject:

<template>
  <button @click="start">Start</button>
  <button @click="stop">Stop</button>
  <video :srcObject.prop="stream" autoplay />
</template>

<script>
export default {
  data: () => ({ stream: null }),
  methods: {
    async start() {
      this.stream = await navigator.mediaDevices.getUserMedia({ video: true })
    },
    stop() {
      this.stream = null
  },
  }
}
</script>

See this comment: #1049 (comment)

@pikax
Copy link
Member Author

pikax commented Apr 26, 2020

@jonaskuske you right, this is actually a bug I spotted when trying to reproduce this issue.

I wasn't thinking straight last night, I will update the PR to reflect the bug I found, thank you.

@pikax pikax marked this pull request as draft April 26, 2020 10:26
@ycmjason
Copy link
Contributor

#1092
Here is my attempt to fix.

yyx990803 added a commit that referenced this pull request May 1, 2020
@yyx990803
Copy link
Member

See 20bc7ba and 98bee59

@yyx990803 yyx990803 closed this May 1, 2020
@pikax pikax deleted the fix/catch_typeError_on_patch_props branch May 5, 2020 20:21
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