Skip to content

Conversation

@cyyynthia
Copy link

This PR improves the compiled code for Vapor components, by omitting unnecessary HTML close tags resulting in a smaller output. Resolves a TODO specified in code comments.

Closing tags are skipped when the element is the last child of its parent. Even when the parent isn't the last element of the grandparent except for formatting elements (as defined by the HTML spec) since they cause issues with reconstruction, and when the parent has the same tag (since the parent's closing tag would actually close the child).

If the above description isn't clear enough, perhaps this table (+ the tests) will shed some light on the compiler's behavior.

Vue template Generated template
<div><span/></div> <div><span>
<div><span/><span/></div> <div><span></span><span>
<div><p><span/></p><span/></div> <div><p><span></p><span>
<div><p><b/></p><span/></div> <div><p><b></b></p><span>
<div><div><span/></div><div/></div> <div><div><span></div><div>
<div><div><div/></div><div/></div> <div><div><div></div></div><div>

@coderabbitai
Copy link

coderabbitai bot commented Jul 20, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zhiyuanzmj zhiyuanzmj added the scope: vapor related to vapor mode label Jul 20, 2025
@github-actions
Copy link

github-actions bot commented Jul 21, 2025

Size Report

Bundles

File Size Gzip Brotli
compiler-dom.global.prod.js 85.2 kB 29.9 kB 26.4 kB
runtime-dom.global.prod.js 108 kB 40.5 kB 36.4 kB
vue.global.prod.js 166 kB 60.5 kB 53.8 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 48 kB 18.8 kB 17.1 kB
createApp 57 kB 21.9 kB 20 kB
createApp + vaporInteropPlugin 88.5 kB (-6.92 kB) 33.2 kB (-1.94 kB) 30 kB (-1.75 kB)
createVaporApp 31.7 kB (-8.88 kB) 12.4 kB (-2.65 kB) 11.3 kB (-2.38 kB)
createSSRApp 61.4 kB 23.7 kB 21.6 kB
defineCustomElement 63.1 kB 23.8 kB 21.7 kB
overall 72.1 kB 27.3 kB 24.9 kB

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jul 21, 2025

Open in StackBlitz

@vue/compiler-core

npm i https://pkg.pr.new/@vue/compiler-core@13667

@vue/compiler-dom

npm i https://pkg.pr.new/@vue/compiler-dom@13667

@vue/compiler-sfc

npm i https://pkg.pr.new/@vue/compiler-sfc@13667

@vue/compiler-ssr

npm i https://pkg.pr.new/@vue/compiler-ssr@13667

@vue/compiler-vapor

npm i https://pkg.pr.new/@vue/compiler-vapor@13667

@vue/reactivity

npm i https://pkg.pr.new/@vue/reactivity@13667

@vue/runtime-core

npm i https://pkg.pr.new/@vue/runtime-core@13667

@vue/runtime-dom

npm i https://pkg.pr.new/@vue/runtime-dom@13667

@vue/runtime-vapor

npm i https://pkg.pr.new/@vue/runtime-vapor@13667

@vue/server-renderer

npm i https://pkg.pr.new/@vue/server-renderer@13667

@vue/shared

npm i https://pkg.pr.new/@vue/shared@13667

vue

npm i https://pkg.pr.new/vue@13667

@vue/compat

npm i https://pkg.pr.new/@vue/compat@13667

commit: 369b70b

@edison1105 edison1105 changed the title fix(compile-vapor): skip unnecessary closing tags in templates refactor(compile-vapor): skip unnecessary closing tags in templates Jul 21, 2025
@edison1105 edison1105 moved this to Vapor in Next Minor Jul 21, 2025
@edison1105
Copy link
Member

Thanks for your PR. Could you please add some tests in dom/template.spec.ts?

@edison1105 edison1105 added the need test The PR has missing test cases. label Jul 25, 2025
@cyyynthia
Copy link
Author

I've added tests in fb678dd. 👍🏻

@edison1105 edison1105 added version: minor and removed need test The PR has missing test cases. labels Sep 23, 2025
@cyyynthia
Copy link
Author

Rebased the changes to solve conflicts 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: vapor related to vapor mode version: minor

Projects

Status: Vapor

Development

Successfully merging this pull request may close these issues.

3 participants