Skip to content

Conversation

@linzhe141
Copy link
Contributor

close #11322

…ind has no expression, an error should be thrown
@github-actions
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

@edison1105 edison1105 Aug 28, 2024

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 it should use the user-passed key here, just like normal elements.
see

@alexchexes
Copy link

Hi! It looks like vuejs/language-tools#4539 depends on this one, and the problem prevents normal work with <template> in some cases.

Is there any chance that this will be merged soon?

@edison1105 edison1105 added scope: compiler 🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. labels Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. scope: compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants