Skip to content

Conversation

edison1105
Copy link
Member

@edison1105 edison1105 commented Sep 24, 2025

close #13920

Summary by CodeRabbit

  • Bug Fixes

    • Ensures component props are registered before compiling inline templates, preventing missing or incorrect prop bindings.
    • Fixes an edge case where prefixed/nested prop names could be referenced incorrectly in inline template mode.
  • Tests

    • Adds a test covering the prefixed props edge case in inline template compilation.

Copy link

coderabbitai bot commented Sep 24, 2025

Walkthrough

Moved generation of the runtime props declaration earlier in compileScript so propsDecl is computed before inline template handling; removed the later duplicate computation. Also added a test covering a props prefixing edge case in inline mode.

Changes

Cohort / File(s) Summary
SFC compiler script flow
packages/compiler-sfc/src/compileScript.ts
Reordered runtime props generation: genRuntimeProps(ctx) assigned to an early-scoped propsDecl before inline template handling; removed the later redundant computation; runtime options now reference the earlier propsDecl.
Tests (inline template edge case)
packages/compiler-sfc/__tests__/compileTemplate.spec.ts
Added test "prefixing props edge case in inline mode" that compiles an inline template with nested Foo.Bar props and asserts the generated script references __props["Foo"]).Bar.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Compile as compileScript()
  participant Ctx as Context
  participant Template as Inline Template Handler
  participant Runtime as Runtime Options Assembler

  rect rgba(220,235,255,0.35)
    Compile->>Ctx: genRuntimeProps(ctx) -> propsDecl (early)
    Note right of Ctx: propsDecl available to subsequent steps
  end

  Compile->>Template: handle inline template (may compile)
  Template->>Compile: template result
  Compile->>Runtime: assemble runtime options using propsDecl
  Runtime->>Compile: runtime options object
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

ready to merge, scope: sfc, :hammer: p3-minor-bug

Suggested reviewers

  • Doctor-wu
  • LittleSound

Poem

I hopped through code at morning light,
Pulled props up front to make things right.
Templates now find bindings near,
Builds and dev render crystal clear.
🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues Check ✅ Passed The changes move the runtime props declaration earlier in the compilation flow and add a test for a prefixed-props edge case in inline mode, which directly targets the failure mode described in issue #13920 where components passed as object properties were compiled incorrectly in production. By registering props before template compilation the compiler will preserve correct prop/component references for object-property props, and the new unit test asserts the expected generated code pattern. These code changes align with the linked issue's objective to make production output match development for object-property component props.
Out of Scope Changes Check ✅ Passed The PR only modifies packages/compiler-sfc/src/compileScript.ts and adds a focused unit test in packages/compiler-sfc/tests/compileTemplate.spec.ts; there are no other file changes, API modifications, or unrelated refactors. Both edits are directly tied to props binding and inline template compilation, so I do not detect out-of-scope changes. The diff appears focused on the linked issue's concerns.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Title Check ✅ Passed The title accurately and concisely describes the primary change: moving props binding registration earlier so they exist before template compilation in inline mode, and it names the affected package (compiler-sfc), which matches the code changes and the added test addressing prefixed props in inline templates.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch edison/fix/13920

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

Copy link

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 101 kB 38.5 kB 34.6 kB
vue.global.prod.js 159 kB 58.6 kB 52.1 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.6 kB 18.2 kB 16.7 kB
createApp 54.6 kB 21.3 kB 19.4 kB
createSSRApp 58.9 kB 23 kB 21 kB
defineCustomElement 59.6 kB 22.8 kB 20.9 kB
overall 68.8 kB 26.4 kB 24.2 kB

Copy link

pkg-pr-new bot commented Sep 24, 2025

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: 23e4a0c

Copy link

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (1)
packages/compiler-sfc/src/compileScript.ts (1)

836-836: Microcopy nit: tweak the comment for clarity

Consider: “ensure props bindings are registered before compiling the template in inline mode”

-  // ensure props bindings register before compile template in inline mode
+  // ensure props bindings are registered before compiling the template in inline mode
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b555f02 and 52aeded.

📒 Files selected for processing (1)
  • packages/compiler-sfc/src/compileScript.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/compiler-sfc/src/compileScript.ts (1)
packages/compiler-sfc/src/script/defineProps.ts (1)
  • genRuntimeProps (141-177)
⏰ 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
🔇 Additional comments (1)
packages/compiler-sfc/src/compileScript.ts (1)

836-837: Add test for member-expression component tags in inlineTemplate mode

Confirmed: props runtime generation is invoked before inline template compile (packages/compiler-sfc/src/compileScript.ts — propsDecl at lines ~793/837/970) and inlineTemplate:true is used in tests, but no fixtures/tests contain member-expression tags like <Foo.Bar/>. Add a focused test under packages/compiler-sfc/tests/compileScript/ that compiles an SFC with a member-expression component tag and { inlineTemplate: true } to prevent regressions.

@edison1105 edison1105 changed the title fix(sfc): ensure props bindings register before compiling template in inline mode fix(compiler-sfc): ensure props bindings register before compiling template in inline mode Sep 24, 2025
@edison1105 edison1105 added ready to merge The PR is ready to be merged. scope: sfc 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. labels Sep 24, 2025
@edison1105 edison1105 changed the title fix(compiler-sfc): ensure props bindings register before compiling template in inline mode fix(compiler-sfc): ensure props bindings register before compiling template Sep 24, 2025
@patroza
Copy link

patroza commented Sep 24, 2025

Works well in our prod build, thanks a lot!

@edison1105 edison1105 merged commit abd5638 into main Sep 24, 2025
16 checks passed
@edison1105 edison1105 deleted the edison/fix/13920 branch September 24, 2025 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. ready to merge The PR is ready to be merged. scope: sfc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When a component is exposed inside an object property, like in the Compound Component pattern, the component is not rendered when built
2 participants