fix(teleport): reapply teleport css vars after root replacement#14594
fix(teleport): reapply teleport css vars after root replacement#14594edison1105 merged 2 commits intominorfrom
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:
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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 (2)
packages/runtime-vapor/__tests__/components/Teleport.spec.ts (1)
1452-1488: Consider adding an assertion for initial CSS var state.The test currently only verifies CSS vars after the toggle. Adding an assertion before
showAlt.value = truewould ensure CSS vars are correctly applied on initial render as well, providing more complete coverage.💡 Suggested improvement
}).render() await nextTick() + // Verify initial CSS vars are applied + const initialEl = target.firstElementChild as HTMLElement + expect(initialEl.tagName).toBe('SPAN') + expect(initialEl.style.getPropertyValue('--color')).toBe('red') + showAlt.value = true await nextTick()🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/runtime-vapor/__tests__/components/Teleport.spec.ts` around lines 1452 - 1488, Add an assertion verifying the initial teleported node's CSS var and element before toggling: after the first await nextTick() (right after render) check target.firstElementChild is a SPAN, has a data-v-owner attribute, and that its style.getPropertyValue('--color') equals 'red' so use the existing variables (target, state, showAlt, useVaporCssVars, VaporTeleport, teleported) to locate the initial element and assert its CSS var is applied before changing showAlt.value.packages/runtime-vapor/src/components/Teleport.ts (1)
155-171: Minor: forEach callback return value flagged by linter.The static analysis tool flags line 166 for returning a value from
forEachcallback. While functionally harmless (forEach ignores return values), the same pattern exists ininitChildren(lines 135-137), so this is consistent with existing code.If you want to address the linter warning for both locations:
🔧 Suggested fix
block.forEach( - node => isVaporComponent(node) && (node.parentTeleport = this), + node => { + if (isVaporComponent(node)) node.parentTeleport = this + }, )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/runtime-vapor/src/components/Teleport.ts` around lines 155 - 171, The linter flags returning a value from the forEach callback in bindChildren (and the similar pattern in initChildren); change the arrow callback from an expression using && that returns the assignment to a block that performs the assignment without returning (e.g. node => { if (isVaporComponent(node)) node.parentTeleport = this } ) so the callback has no return value; update both bindChildren and initChildren to use this explicit if-block (or a for...of loop) while keeping the same conditions and assignment to parentTeleport.
🤖 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/runtime-vapor/__tests__/components/Teleport.spec.ts`:
- Around line 1452-1488: Add an assertion verifying the initial teleported
node's CSS var and element before toggling: after the first await nextTick()
(right after render) check target.firstElementChild is a SPAN, has a
data-v-owner attribute, and that its style.getPropertyValue('--color') equals
'red' so use the existing variables (target, state, showAlt, useVaporCssVars,
VaporTeleport, teleported) to locate the initial element and assert its CSS var
is applied before changing showAlt.value.
In `@packages/runtime-vapor/src/components/Teleport.ts`:
- Around line 155-171: The linter flags returning a value from the forEach
callback in bindChildren (and the similar pattern in initChildren); change the
arrow callback from an expression using && that returns the assignment to a
block that performs the assignment without returning (e.g. node => { if
(isVaporComponent(node)) node.parentTeleport = this } ) so the callback has no
return value; update both bindChildren and initChildren to use this explicit
if-block (or a for...of loop) while keeping the same conditions and assignment
to parentTeleport.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0520833f-34b7-4c0b-952b-d299b65640ff
📒 Files selected for processing (2)
packages/runtime-vapor/__tests__/components/Teleport.spec.tspackages/runtime-vapor/src/components/Teleport.ts
b0826dd to
b981bb7
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/runtime-vapor/src/components/Teleport.ts (1)
149-153: Avoid returning values fromforEachcallbacks.The
&&expression returns a value thatforEachignores. Use an explicit conditional for clarity.♻️ Suggested fix
} else if (isArray(block)) { - block.forEach( - node => isVaporComponent(node) && (node.parentTeleport = this), - ) + block.forEach(node => { + if (isVaporComponent(node)) { + node.parentTeleport = this + } + }) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/runtime-vapor/src/components/Teleport.ts` around lines 149 - 153, The forEach callback is using a short-circuit expression that returns a value (block.forEach(node => isVaporComponent(node) && (node.parentTeleport = this))), which is ignored and unclear; change the callback to an explicit conditional so it doesn't return a value — e.g., in the Teleport code path that checks isArray(block) replace the arrow expression with a body that does if (isVaporComponent(node)) { node.parentTeleport = this } to set parentTeleport without returning a value.
🤖 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/runtime-vapor/src/components/Teleport.ts`:
- Around line 149-153: The forEach callback is using a short-circuit expression
that returns a value (block.forEach(node => isVaporComponent(node) &&
(node.parentTeleport = this))), which is ignored and unclear; change the
callback to an explicit conditional so it doesn't return a value — e.g., in the
Teleport code path that checks isArray(block) replace the arrow expression with
a body that does if (isVaporComponent(node)) { node.parentTeleport = this } to
set parentTeleport without returning a value.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2bbd577b-7aba-4374-bbb6-69ed16612225
📒 Files selected for processing (2)
packages/runtime-vapor/__tests__/components/Teleport.spec.tspackages/runtime-vapor/src/components/Teleport.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/runtime-vapor/tests/components/Teleport.spec.ts
Summary by CodeRabbit
New Features
useVaporCssVarspublic API to enable reactive CSS variable propagation in teleported elements.Bug Fixes
Tests