-
-
Notifications
You must be signed in to change notification settings - Fork 9k
fix(compiler-ssr): handle ssr attr fallthrough when preserve whitespace #12304
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
base: main
Are you sure you want to change the base?
Conversation
Size ReportBundles
Usages
|
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
packages/compiler-ssr/src/transforms/ssrInjectFallthroughAttrs.ts
Outdated
Show resolved
Hide resolved
WalkthroughUpdates SSR fallthrough attribute injection to ignore comment and whitespace nodes when detecting single-child fallthroughs; adds a test asserting correct rendering with Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Compiler as SSR Compiler
participant Transform as ssrInjectFallthroughAttrs
participant AST as Component AST
participant Renderer as SSR Renderer
Compiler->>Transform: pass AST for component
note right of Transform `#DFF2E1`: filter children\n(using isCommentOrWhitespace)
Transform->>AST: filter children (ignore comments & whitespace)
alt single visible child detected
Transform->>AST: inject fallthrough attrs (ssrRenderAttrs)
else multiple/none
Transform-->>AST: no injection
end
Transform->>Renderer: emit SSR code
Renderer->>Renderer: render final HTML
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (1)
packages/compiler-ssr/src/transforms/ssrInjectFallthroughAttrs.ts (1)
13-16: Fix the filterChild function to preserve non-whitespace TEXT nodes at the root level.The current implementation incorrectly filters out all TEXT nodes, causing fallthrough attributes to be injected when there's actual text content at the root level. This violates Vue 3's single-root behavior: multiple root nodes (including non-whitespace text) should not receive fallthrough attributes.
The missing test case confirms this scenario is not covered: root-level non-whitespace text combined with v-if/v-else branches. Apply the suggested fix at
packages/compiler-ssr/src/transforms/ssrInjectFallthroughAttrs.tslines 13-16:const filterChild = (node: ParentNode) => node.children.filter( - n => n.type !== NodeTypes.COMMENT && n.type !== NodeTypes.TEXT, + n => + n.type !== NodeTypes.COMMENT && + (n.type !== NodeTypes.TEXT || n.content.trim() !== ''), )
🧹 Nitpick comments (1)
packages/compiler-ssr/__tests__/ssrFallthroughAttrs.spec.ts (1)
51-74: LGTM! Test validates the fix for issue #8072.The test correctly validates that when
whitespace: 'preserve'is enabled, whitespace between v-if/v-else elements doesn't prevent fallthrough attribute injection. Both branches properly receive_ssrRenderAttrs(_attrs)in the output.Consider adding an edge case test to ensure non-whitespace text content at the root level prevents fallthrough attribute injection:
test('should not inject with non-whitespace text and v-if', () => { expect( compile( `Text content <div v-if="condition">Branch A</div> <div v-else>Branch B</div>`, { whitespace: 'preserve' } ).code ).not.toContain('_ssrRenderAttrs(_attrs)') })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/compiler-ssr/__tests__/ssrFallthroughAttrs.spec.ts(1 hunks)packages/compiler-ssr/src/transforms/ssrInjectFallthroughAttrs.ts(1 hunks)
close #8072
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.