-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
fix(compiler-ssr): expand v-model option
selected inclusion logic
#13963
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?
fix(compiler-ssr): expand v-model option
selected inclusion logic
#13963
Conversation
WalkthroughReworks SSR v-model option value extraction to derive values from bound attributes, text directives, or collapsed text/interpolations; adds collapse utility; updates selected-state codegen; and adds extensive SSR tests for / scenarios. No public API changes.
Changes
Cohort / File(s)
Summary
SSR v-model transformpackages/compiler-ssr/src/transforms/ssrVModel.ts
Adds internal OptionValue type and findOptionValue() to resolve option values from value bindings, v-text, or collapsed text/interpolations; introduces collapseTextBetweenComments(); updates imports (TemplateLiteral, TextNode, createTemplateLiteral, findDir); and adjusts selected-state SSR codegen to use the derived value source.
SSR compiler testspackages/compiler-ssr/__tests__/ssrVModel.spec.ts
Adds many new SSR unit tests and inline snapshots covering options with literal text, trimmed/spaced text, interpolations, v-text, v-for, slots/content, optgroups, and template/conditional combinations to validate option value derivation and selected logic.
SSR renderer testspackages/server-renderer/__tests__/ssrDirectives.spec.ts
Adds two tests verifying interpolation and v-text inside <option> render expected text and selected state in SSR output.
Sequence Diagram(s)
sequenceDiagram
autonumber
participant Template as Template (AST)
participant Compiler as SSR Compiler
participant Transform as ssrVModel Transform
participant Helper as Utilities (collapseTextBetweenComments)
participant Codegen as SSR Codegen
participant Runtime as SSR Helpers
Template->>Compiler: parse -> AST
Compiler->>Transform: apply v-model transform on <select>/<option>
Transform->>Transform: findOptionValue()\n- if `value` binding -> use bound expr\n- else if `v-text` dir -> use text expr\n- else -> call Helper to collapse TEXT/INTERPOLATION/COMMENT\nHelper-->>Transform: sequence or TemplateLiteral value
Transform->>Codegen: emit selected logic using derived value\nCodegen->>Runtime: reference _ssrLooseContain/_ssrLooseEqual helpers
Note right of Runtime: Helpers evaluate at render time to set `selected`
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
#13487 — Modifies the same packages/compiler-ssr/src/transforms/ssrVModel.ts area to improve SSR handling of <select>/<option> value extraction and child processing.
Suggested labels
ready to merge, 🔨 p3-minor-bug
Poem
I’m a rabbit in the build, nibbling bits of text,
I fold interpolations, chase comments next.
Value bound or written, I tuck it neat—
Then hop to mark the selected seat. 🐇✨
Pre-merge checks and finishing touches
❌ Failed checks (1 warning)
Check name
Status
Explanation
Resolution
Docstring Coverage
|
Size ReportBundles
Usages
|
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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/compiler-ssr/__tests__/ssrVModel.spec.ts
(1 hunks)packages/compiler-ssr/src/transforms/ssrVModel.ts
(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/compiler-ssr/src/transforms/ssrVModel.ts (3)
packages/compiler-core/src/ast.ts (9)
createConditionalExpression
(758-772)createCallExpression
(728-739)ExpressionNode
(91-91)TemplateLiteral
(449-452)PlainElementNode
(140-149)createSimpleExpression
(685-698)createTemplateLiteral
(801-809)TemplateChildNode
(93-102)TextNode
(176-179)packages/compiler-ssr/src/runtimeHelpers.ts (3)
SSR_INCLUDE_BOOLEAN_ATTR
(15-17)SSR_LOOSE_CONTAIN
(19-19)SSR_LOOSE_EQUAL
(18-18)packages/compiler-core/src/utils.ts (2)
findProp
(299-320)findDir
(282-297)
⏰ 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). (4)
- GitHub Check: Redirect rules
- GitHub Check: Header rules
- GitHub Check: Pages changed
- GitHub Check: test / unit-test-windows
@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: |
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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/compiler-ssr/__tests__/ssrVModel.spec.ts
(1 hunks)packages/compiler-ssr/src/transforms/ssrVModel.ts
(4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/compiler-ssr/tests/ssrVModel.spec.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/compiler-ssr/src/transforms/ssrVModel.ts (3)
packages/compiler-core/src/ast.ts (8)
createConditionalExpression
(758-772)createCallExpression
(728-739)ExpressionNode
(91-91)TemplateLiteral
(449-452)createSimpleExpression
(685-698)createTemplateLiteral
(801-809)TemplateChildNode
(93-102)TextNode
(176-179)packages/compiler-ssr/src/runtimeHelpers.ts (3)
SSR_INCLUDE_BOOLEAN_ATTR
(15-17)SSR_LOOSE_CONTAIN
(19-19)SSR_LOOSE_EQUAL
(18-18)packages/compiler-core/src/utils.ts (2)
findProp
(299-320)findDir
(282-297)
⏰ 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). (3)
- GitHub Check: Redirect rules
- GitHub Check: Header rules
- GitHub Check: Pages changed
The following example has a bug |
@edison1105 updated! |
close #13436
Expand cases under which the
selected
attribute is added onto anoption
tag in SSR:option
v-text
An additional side effect of this PR is to fix the current behavior showcased by this playground example, which I believe to be a bug: link
Example
Summary by CodeRabbit
New Features
Bug Fixes
Tests