Skip to content

Conversation

linzhe141
Copy link
Contributor

@linzhe141 linzhe141 commented Jun 26, 2024

close #11230

Summary by CodeRabbit

  • New Features

    • Improved hydration behavior for disabled Teleport components when their target is undefined during server-side rendering.
  • Tests

    • Added tests (two occurrences) validating hydration of disabled Teleport components with an undefined target to ensure rendered markers and content match expectations.

@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?

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.4 kB (+22 B) 34.5 kB (-13 B)
vue.global.prod.js 159 kB (+69 B) 58.5 kB (+21 B) 52.2 kB (+112 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.5 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 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
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: 84fa547

@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

Hydration logic for Teleport was extended to explicitly handle disabled teleports both when a target is resolved and when it is undefined. Two SSR tests were added verifying hydration of a disabled Teleport with an undefined target; no public API changes were made.

Changes

Cohort / File(s) Change Summary
Tests
packages/runtime-core/__tests__/hydration.spec.ts
Added two occurrences of a test that verifies SSR hydration for a disabled Teleport with to undefined.
Teleport hydration
packages/runtime-core/src/components/Teleport.ts
Introduced hydrateDisabledTeleport helper and restructured hydrateTeleport to reuse computed disabled state and handle disabled teleports both with and without resolved targets.

Sequence Diagram(s)

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

    Note over SSR,Container: server-rendered HTML contains teleport markers
    SSR->>Container: renderToString -> HTML with <!--teleport start-->/<--teleport end-->
    App->>Container: mount()
    App->>Teleport: hydrateTeleport(vnode)
    Teleport->>Teleport: compute disabled state
    alt target resolved
        Teleport->>Teleport: if disabled -> hydrateDisabledTeleport(startNode, nextSibling)
    else no target
        Teleport->>Teleport: if disabled and children array -> hydrateDisabledTeleport(curNode, curNode.nextSibling)
    end
    Teleport->>Container: hydrate children in-place and set anchors/targets
    Teleport->>App: hydration complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Assessment against linked issues

Objective (issue) 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)

Assessment against linked issues: Out-of-scope changes

(No out-of-scope functional changes detected related to the linked issue objectives.)

Suggested labels

scope:hydration

Poem

I’m a rabbit in the render tree,
Hopping where the teleports be.
Disabled, lost—now hydrated right,
Markers hold my little sprite.
Bounce and munch, the DOM’s in tune,
I celebrate beneath the moon 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@edison1105
Copy link
Member

/ecosystem-ci run

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 (2)
packages/runtime-core/__tests__/hydration.spec.ts (2)

2360-2382: Stabilize assertion by removing indentation-sensitive whitespace.

The equality currently depends on template indentation. Inline the template text and assert without leading/trailing spaces to avoid brittle failures across compiler whitespace tweaks.

-      template: `
-          <Teleport :to="undefined" :disabled="true">
-            <div v-if="isOpen">
-              Menu is open...
-            </div>
-          </Teleport>`,
+      template: `<Teleport :to="undefined" :disabled="true"><div v-if="isOpen">Menu is open...</div></Teleport>`,
@@
-      expect(container.innerHTML).toBe(
-        `<!--teleport start--><div> Menu is open... </div><!--teleport end-->`,
-      )
+      expect(container.innerHTML).toBe(
+        `<!--teleport start--><div>Menu is open...</div><!--teleport end-->`,
+      )
+      expect(`Hydration node mismatch`).not.toHaveBeenWarned()
+      expect(`Hydration children mismatch`).not.toHaveBeenWarned()

2360-2360: Align test name with suite style.

Match nearby Teleport tests’ naming for consistency.

-    test('with disabled teleport + undefined target', async () => {
+    test('Teleport (disabled + undefined target)', async () => {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

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

📒 Files selected for processing (1)
  • packages/runtime-core/__tests__/hydration.spec.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/runtime-core/__tests__/hydration.spec.ts (2)
packages/runtime-core/src/apiCreateApp.ts (1)
  • App (33-119)
packages/runtime-dom/src/index.ts (1)
  • createSSRApp (148-165)
🪛 ast-grep (0.38.6)
packages/runtime-core/__tests__/hydration.spec.ts

[warning] 2373-2373: Direct modification of innerHTML or outerHTML properties detected. Modifying these properties with unsanitized user input can lead to XSS vulnerabilities. Use safe alternatives or sanitize content first.
Context: container.innerHTML = await renderToString(h(App))
Note: [CWE-79] Improper Neutralization of Input During Web Page Generation [REFERENCES]
- https://owasp.org/www-community/xss-filter-evasion-cheatsheet
- https://cwe.mitre.org/data/definitions/79.html

(dom-content-modification)


[warning] 2373-2373: Direct HTML content assignment detected. Modifying innerHTML, outerHTML, or using document.write with unsanitized content can lead to XSS vulnerabilities. Use secure alternatives like textContent or sanitize HTML with libraries like DOMPurify.
Context: container.innerHTML = await renderToString(h(App))
Note: [CWE-79] Improper Neutralization of Input During Web Page Generation [REFERENCES]
- https://www.dhairyashah.dev/posts/why-innerhtml-is-a-bad-idea-and-how-to-avoid-it/
- https://cwe.mitre.org/data/definitions/79.html

(unsafe-html-content-assignment)

⏰ 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). (1)
  • GitHub Check: test / e2e-test
🔇 Additional comments (1)
packages/runtime-core/__tests__/hydration.spec.ts (1)

2373-2376: innerHTML usage in test is fine.

Assigning SSR output to innerHTML is standard in this suite and safe here (trusted source). No change needed despite static-analysis noise.

@vuejs vuejs deleted a comment from edison1105 Sep 1, 2025
@vue-bot
Copy link
Contributor

vue-bot commented Sep 1, 2025

📝 Ran ecosystem CI: Open

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

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