fix(compiler-vapor): use createElement path for plain template#14744
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Size ReportBundles
Usages
|
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/compiler-vapor
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/runtime-vapor
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/compiler-vapor/src/transforms/vText.ts (1)
52-73: Reuse the synthetic childidforSET_TEXT.Lines 68-69 recompute the target from
context.dynamic.children[node.children.length]even thoughregisterSyntheticTextChild()already returned the inserted node id. Threading thatidthrough keeps this transform decoupled from child-slot bookkeeping and makes the invalid-children path less fragile.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/compiler-vapor/src/transforms/vText.ts` around lines 52 - 73, The transform recomputes the target element for the SET_TEXT effect from context.dynamic.children[node.children.length] instead of reusing the synthetic child id returned by registerSyntheticTextChild(); change the code so the id produced by registerSyntheticTextChild(context, '') (call site: registerSyntheticTextChild) is preserved in an outer-scope variable and used as the element when building the IRNodeTypes.SET_TEXT effect (instead of context.dynamic.children[node.children.length]!.id!), so that the SET_TEXT's element is the same id passed into the earlier context.registerOperation that inserted the synthetic text child; ensure the id is declared before the if (useCreateElement) branch and assigned inside it so it’s available later when creating the effect.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/compiler-vapor/src/transforms/vText.ts`:
- Around line 52-73: The transform recomputes the target element for the
SET_TEXT effect from context.dynamic.children[node.children.length] instead of
reusing the synthetic child id returned by registerSyntheticTextChild(); change
the code so the id produced by registerSyntheticTextChild(context, '') (call
site: registerSyntheticTextChild) is preserved in an outer-scope variable and
used as the element when building the IRNodeTypes.SET_TEXT effect (instead of
context.dynamic.children[node.children.length]!.id!), so that the SET_TEXT's
element is the same id passed into the earlier context.registerOperation that
inserted the synthetic text child; ensure the id is declared before the if
(useCreateElement) branch and assigned inside it so it’s available later when
creating the effect.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d8fb9b3d-b000-4d1a-8674-88562cbae6f4
⛔ Files ignored due to path filters (2)
packages/compiler-vapor/__tests__/transforms/__snapshots__/transformElement.spec.ts.snapis excluded by!**/*.snappackages/compiler-vapor/__tests__/transforms/__snapshots__/vText.spec.ts.snapis excluded by!**/*.snap
📒 Files selected for processing (9)
packages/compiler-vapor/__tests__/transforms/transformElement.spec.tspackages/compiler-vapor/__tests__/transforms/vText.spec.tspackages/compiler-vapor/src/generators/component.tspackages/compiler-vapor/src/ir/index.tspackages/compiler-vapor/src/transforms/transformChildren.tspackages/compiler-vapor/src/transforms/transformElement.tspackages/compiler-vapor/src/transforms/transformText.tspackages/compiler-vapor/src/transforms/vText.tspackages/runtime-vapor/__tests__/component.spec.ts
4144d2f to
3b70a2e
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/compiler-vapor/src/transforms/vText.ts (1)
67-73: Non-null assertion onid!is safe but could be clearer.At line 69,
useCreateElement ? id! : context.reference()uses a non-null assertion. While this is safe becauseidis always assigned whenuseCreateElementis true (lines 41 and 54), the control flow is split across two separateifblocks (literal vs non-literal).The code is correct as-is, but if you want to make the invariant more explicit, you could restructure to avoid the assertion.
♻️ Optional: Extract common element reference pattern
+ const textElement = useCreateElement ? id! : context.reference() context.registerEffect([exp], { type: IRNodeTypes.SET_TEXT, - element: useCreateElement ? id! : context.reference(), + element: textElement, values: [exp], generated: !useCreateElement, isComponent, })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/compiler-vapor/src/transforms/vText.ts` around lines 67 - 73, The non-null assertion id! in the context.registerEffect call hides the invariant that id is set when useCreateElement is true; make that invariant explicit by computing an elementRef beforehand (useCreateElement ? id : context.reference()) and ensure id is checked or assigned before using it (e.g., throw or assert if id is unexpectedly undefined), then pass elementRef into context.registerEffect; update references to IRNodeTypes.SET_TEXT, context.registerEffect, id, useCreateElement, and context.reference() accordingly so no non-null assertion is required.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/compiler-vapor/__tests__/abbreviation.spec.ts`:
- Around line 182-192: Restore the commented-out <template> assertions in the
abbreviation test by re-enabling the two checkAbbr calls and updating their
expected outputs to match the new createElement-path semantics: use the
checkAbbr helper to assert the input strings containing <template> still produce
the updated abbreviation and full-render outputs (adjust the second and third
string arguments to reflect the createElement-style compilation instead of the
old native <template> form); locate the two commented checkAbbr invocations
around the existing tests and replace their expected abbreviated and full HTML
strings to the new compiled form produced by the createElement path.
---
Nitpick comments:
In `@packages/compiler-vapor/src/transforms/vText.ts`:
- Around line 67-73: The non-null assertion id! in the context.registerEffect
call hides the invariant that id is set when useCreateElement is true; make that
invariant explicit by computing an elementRef beforehand (useCreateElement ? id
: context.reference()) and ensure id is checked or assigned before using it
(e.g., throw or assert if id is unexpectedly undefined), then pass elementRef
into context.registerEffect; update references to IRNodeTypes.SET_TEXT,
context.registerEffect, id, useCreateElement, and context.reference()
accordingly so no non-null assertion is required.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 089a4740-427c-466f-af2f-f05784722c92
⛔ Files ignored due to path filters (2)
packages/compiler-vapor/__tests__/transforms/__snapshots__/transformElement.spec.ts.snapis excluded by!**/*.snappackages/compiler-vapor/__tests__/transforms/__snapshots__/transformText.spec.ts.snapis excluded by!**/*.snap
📒 Files selected for processing (7)
packages/compiler-vapor/__tests__/abbreviation.spec.tspackages/compiler-vapor/__tests__/transforms/transformElement.spec.tspackages/compiler-vapor/__tests__/transforms/transformText.spec.tspackages/compiler-vapor/src/transforms/transformElement.tspackages/compiler-vapor/src/transforms/transformText.tspackages/compiler-vapor/src/transforms/vText.tspackages/runtime-vapor/__tests__/component.spec.ts
✅ Files skipped from review due to trivial changes (1)
- packages/compiler-vapor/tests/transforms/transformText.spec.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- packages/compiler-vapor/tests/transforms/transformElement.spec.ts
- packages/runtime-vapor/tests/component.spec.ts
- packages/compiler-vapor/src/transforms/transformText.ts
Summary by CodeRabbit
Tests
<template>elements, custom elements, text rendering, andv-textdirective behaviorBug Fixes
v-textdirective compilation for template elements