core icon indicating copy to clipboard operation
core copied to clipboard

refactor(compile-vapor): skip unnecessary closing tags in templates

Open cyyynthia opened this issue 5 months ago โ€ข 6 comments

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>

cyyynthia avatar Jul 20 '25 20:07 cyyynthia

[!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.

coderabbitai[bot] avatar Jul 20 '25 20:07 coderabbitai[bot]

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

github-actions[bot] avatar Jul 21 '25 02:07 github-actions[bot]

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

pkg-pr-new[bot] avatar Jul 21 '25 02:07 pkg-pr-new[bot]

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

edison1105 avatar Jul 25 '25 03:07 edison1105

I've added tests in fb678dd4ecfabebdcad4b6424f2e2fdbbbb9b528. ๐Ÿ‘๐Ÿป

cyyynthia avatar Jul 26 '25 08:07 cyyynthia

Rebased the changes to solve conflicts ๐Ÿ˜„

cyyynthia avatar Nov 30 '25 10:11 cyyynthia