8000 fix(Teleport): hydrate disabled Teleport with undefined target by linzhe141 · Pull Request #11235 · vuejs/core · GitHub
[go: up one dir, main page]

Skip to content

fix(Teleport): hydrate disabled Teleport with undefined target #11235

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

linzhe141
Copy link
Contributor
@linzhe141 linzhe141 commented Jun 26, 2024

close #11230

Summary by CodeRabbit

  • New Features

    • Improved hydration support for Teleport components that are disabled and have an undefined target during server-side rendering.
  • Tests

    • Added a test case to verify correct hydration behavior for disabled Teleport components with an undefined target.

@linzhe141 linzhe141 changed the title fix(runtime-core): When hydrateTeleport, the targetNode of disabled Teleport should use the node of nextSibling fix(runtime-core): When hydrate Teleport, the targetNode of disabled Teleport should use the node of nextSibling Jun 27, 2024
@TotomInc
Copy link
TotomInc commented Jul 6, 2024

Hello, thanks for the PR. Is there any chance it will get merged?

8000
@@ -406,6 +406,21 @@ function hydrateTeleport(
}
updateCssVars(vnode)
}
if (!target && isTeleportDisabled(vnode.props)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!target && isTeleportDisabled(vnode.props)) {
else if (isTeleportDisabled(vnode.props)) {
if (vnode.shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
vnode.anchor = hydrateChildren(
nextSibling(node),
vnode,
parentNode(node)!,
parentComponent,
parentSuspense,
slotScopeIds,
optimized,
)
vnode.targetStart = node
vnode.targetAnchor = nextSibling(node)
}
}

Copy link
Member
@edison1105 edison1105 Aug 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to extract a hydrateDisabledTeleport method.
Could you please add a test case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your review, I will improve it

Copy link
github-actions bot commented Aug 9, 2024

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 101 kB (+69 B) 38.3 kB (+23 B) 34.6 kB (+33 B)
vue.global.prod.js 159 kB (+69 B) 58.5 kB (+22 B) 52.1 kB (+47 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.5 kB 18.2 kB 16.7 kB
createApp 54.5 kB 21.2 kB 19.4 kB
createSSRApp 58.7 kB 22.9 kB 20.9 kB
defineCustomElement 59.4 kB 22.8 kB 20.8 kB
overall 68.5 kB 26.4 kB 24 kB

@linzhe141 linzhe141 force-pushed the fix-hydrate-teleport branch from bd3ac0e to 49581b7 Compare August 9, 2024 14:01
@linzhe141 linzhe141 requested a review from edison1105 August 10, 2024 11:33
@TotomInc
Copy link

Sorry for the bump, but is there any chance it will get merged? Thanks a lot for your work @linzhe141 🙏

@linzhe141
Copy link
Contributor Author

Sorry for the bump, but is there any chance it will get merged? Thanks a lot for your work @linzhe141 🙏

Maybe the current modification is not correct, so it may not be merged.

@edison1105
Copy link
Member

/ecosystem-ci run

@edison1105 edison1105 removed the need test The PR has missing test cases. label Sep 20, 2024
@edison1105 edison1105 changed the title fix(runtime-core): When hydrate Teleport, the targetNode of disabled Teleport should use the node of nextSibling fix(Teleport): hydrate disabled Teleport with undefined target Sep 20, 2024
@edison1105 edison1105 added the ready to merge The PR is ready to be merged. label Sep 20, 2024
@vue-bot
Copy link
Contributor
vue-bot commented Sep 20, 2024

📝 Ran ecosystem CI: Open

suite result latest scheduled
language-tools failure failure
nuxt failure success
pinia success success
primevue success success
quasar failure success
radix-vue success success
router success success
test-utils success success
vant failure success
vite-plugin-vue success success
vitepress success success
vue-i18n success success
vue-macros failure failure
vuetify success success
vueuse success success
vue-simple-compiler success success

Copy link
pkg-pr-new bot commented Sep 20, 2024

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: 1bbdc3b

@TotomInc
Copy link

Any update on this one? There's still dependencies relying on this changes 🙏

@edison1105 edison1105 added 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. and removed 🔩 p2-edge-case labels Jul 1, 2025
Copy link
coderabbitai bot commented Jul 1, 2025

Walkthrough

A new test was added to verify SSR hydration of a disabled Teleport with an undefined target. The Teleport hydration logic was updated to explicitly handle disabled state both with and without a resolved target, ensuring correct vnode property assignments and hydration of children in these scenarios.

Changes

File(s) Change Summary
packages/runtime-core/tests/hydration.spec.ts Added a test for SSR hydration with a disabled Teleport and undefined target.
packages/runtime-core/src/components/Teleport.ts Refactored and extended hydration logic to handle disabled Teleports with or without a target.

Sequence Diagram(s)

sequenceDiagram
    participant SSR as Server
    participant DOM as DOM Container
    participant App as Vue App
    participant Teleport as Teleport Component

    SSR->>DOM: Render Teleport (disabled, target undefined) to string
    App->>DOM: Mount app on container
    App->>Teleport: Initialize Teleport (disabled, target undefined)
    Teleport->>Teleport: Detect disabled & undefined target
    Teleport->>Teleport: Hydrate children in place (using parent container)
    Teleport->>App: Complete hydration
Loading

Assessment against linked issues

Objective Addressed Explanation
Fix hydration for conditional children inside disabled Teleport with undefined target (#11230)
Prevent runtime error when toggling Teleport with disabled and no target (#11230)

Poem

A teleport, lost, with no place to go,
Disabled and drifting, its target a "no".
Hydration now knows just what to do—
Children appear, as if on cue!
No errors, no fuss, just seamless delight,
The rabbit hops on, code working right! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ba391f5 and 1bbdc3b.

📒 Files selected for processing (2)
  • packages/runtime-core/__tests__/hydration.spec.ts (1 hunks)
  • packages/runtime-core/src/components/Teleport.ts (2 hunks)
🔇 Additional comments (5)
packages/runtime-core/src/components/Teleport.ts (4)

409-426: LGTM! Helper function addresses previous feedback.

The extracted hydrateDisabledTeleport helper function successfully addresses the past review comment from edison1105. The implementation correctly hydrates children and sets the required vnode properties (anchor, targetStart, targetAnchor).


432-432: Good optimization: compute disabled state once.

Computing the disabled state earlier and reusing it throughout the function is more efficient than calling isTeleportDisabled(vnode.props) multiple times.


440-445: Clean refactor using the new helper function.

The disabled teleport handling with a resolved target now correctly delegates to the hydrateDisabledTeleport helper, passing appropriate target boundaries.


487-491: Correct implementation for disabled teleport without target.

This new branch properly handles the core issue described in the PR title - hydrating a disabled Teleport when the target is undefined. The logic correctly uses the current node as both targetStart and its next sibling as targetAnchor.

packages/runtime-core/__tests__/hydration.spec.ts (1)

2268-2291: Comprehensive test case addresses the PR scenario.

This test effectively covers the core issue described in the PR title - hydrating a disabled Teleport with an undefined target. The test:

  1. Creates a Teleport with to="undefined" and disabled="true"
  2. Performs SSR hydration correctly
  3. Tests reactive state changes
  4. Verifies the expected DOM structure with teleport markers

This addresses the previous review feedback from edison1105 requesting a test case.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: teleport
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Conditional children inside an optional Teleport (with disabled) doesn't work
4 participants
0