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(compiler-core): When the user uses the key inappropriately in the template, a compilation error should be thrown. #11323

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

linzhe141
Copy link
Contributor

close #11322

…ind has no expression, an error should be thrown
Copy link

github-actions bot commented Jul 9, 2024

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 89.4 kB 34.2 kB 30.9 kB
vue.global.prod.js 146 kB (+6 B) 53.6 kB (+20 B) 47.8 kB (+26 B)

Usages

Name Size Gzip Brotli
createApp 51.3 kB 20.1 kB 18.3 kB
createSSRApp 54.7 kB 21.5 kB 19.5 kB
defineCustomElement 53.6 kB 20.9 kB 18.9 kB
overall 65.1 kB 25.1 kB 22.7 kB

@so1ve
Copy link
Member

so1ve commented Jul 10, 2024

What about v-if?

@linzhe141
Copy link
Contributor Author

What about v-if? v-if 怎么样?

The key of v-if is set internally. If the user manually sets the key, it will not take effect.

image

image

@so1ve
Copy link
Member

so1ve commented Jul 10, 2024

Thanks for the explanation, perhaps we'd add a warning or improve the document

@linzhe141 linzhe141 changed the title fix(compiler-core): When using v-for and v-bind in a template, if v-bind has no expression, an error should be thrown fix(compiler-core): When a user uses a key improperly in a template, a compilation error should be thrown. Jul 12, 2024
@linzhe141 linzhe141 changed the title fix(compiler-core): When a user uses a key improperly in a template, a compilation error should be thrown. fix(compiler-core): When the user uses the key inappropriately in the template, a compilation error should be thrown. Jul 12, 2024
if ((__DEV__ || !__BROWSER__) && isTemplate) {
const keyProp = findProp(node, `key`, false, true)
if (keyProp) {
context.onError(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be thrown an error. I think I should use the user-passed key here, just like normal elements.
see

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.

Doesn't throw on invalid code like <template v-if :key="">
3 participants