8000 fix(ssr): ensure empty slots render as a comment node in Transition by edison1105 · Pull Request #13396 · vuejs/core · GitHub
[go: up one dir, main page]

Skip to content

fix(ssr): ensure empty slots render as a comment node in Transition #13396

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 6 commits into
base: main
Choose a base branch
from

Conversation

edison1105
Copy link
Member
@edison1105 edison1105 commented May 28, 2025

close #13394

Summary by CodeRabbit

  • New Features
    • Improved server-side rendering to correctly handle transition components with empty slots, ensuring a placeholder comment is emitted when no content is present.
  • Tests
    • Added new test cases to verify correct hydration and SSR output for transitions with initially empty content.

Copy link
coderabbitai bot commented May 28, 2025

Walkthrough

The changes introduce handling for SSR rendering and hydration of <Transition appear> components with empty content. A new branch in the SSR renderer emits a comment node placeholder when a transition slot is empty. Test cases are added to verify correct SSR output and hydration behavior, ensuring no errors occur in this scenario.

Changes

Files Change Summary
packages/runtime-core/tests/hydration.spec.ts Added a test for hydration with <Transition appear> and empty content.
packages/server-renderer/src/helpers/ssrRenderSlot.ts Modified ssrRenderSlotInner to emit a comment node when rendering a transition with empty content.
packages/server-renderer/tests/ssrSlot.spec.ts Added tests to verify SSR output for <transition> with empty slot emits a comment node, with and without appear.

Sequence Diagram(s)

sequenceDiagram
    participant SSR_Renderer
    participant Output_Buffer

    SSR_Renderer->>SSR_Renderer: Render <transition> with empty slot and transition=true
    SSR_Renderer-->>Output_Buffer: Push '<!---->' (comment node)
Loading
sequenceDiagram
    participant Test
    participant App
    participant DOM

    Test->>App: Mount <Transition appear> with empty content
    App->>DOM: Hydrate as comment node
    Test->>App: Set show=false
    App->>DOM: Update content to text node "foo"
    Test->>DOM: Assert correct node and no hydration warnings
Loading

Assessment against linked issues

Objective Addressed Explanation
Correct SSR rendering for <Transition appear> with empty content (#13394)
Correct hydration of <Transition appear> with empty content, ensuring no errors (#13394)
Hydration does not emit mismatch warnings or throw errors in this scenario (#13394)

Poem

Oh, hoppy day for transitions' plight,
With empty slots, now all is right!
No errors, no warnings, just comment nodes bloom,
Hydration proceeds, no sign of doom.
The rabbit leaps, the tests all pass—
SSR and DOM, in harmony at last!
🐇✨


📜 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 3f95d11 and c4e3d00.

📒 Files selected for processing (1)
  • packages/server-renderer/__tests__/ssrSlot.spec.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/server-renderer/tests/ssrSlot.spec.ts
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules
  • GitHub Check: Header rules
  • GitHub Check: Pages changed
✨ 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 re 8000 views 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.

Copy link
pkg-pr-new bot commented May 28, 2025

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: c4e3d00

Copy link
github-actions bot commented May 28, 2025

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 101 kB 38.3 kB 34.5 kB
vue.global.prod.js 159 kB 58.5 kB 52.1 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.6 kB 18.2 kB 16.6 kB
createApp 54.5 kB 21.2 kB 19.4 kB
createSSRApp 58.8 kB 23 kB 20.9 kB
defineCustomElement 59.5 kB 22.8 kB 20.8 kB
overall 68.6 kB 26.4 kB 24.1 kB

@edison1105 edison1105 added scope: transition 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. scope:hydration ready to merge The PR is ready to be merged. labels May 28, 2025
@skirtles-code
Copy link
Contributor

While the initial hydration is no longer throwing an error, it seems that subsequent updates still fail:

There are also problems in this case, which doesn't use appear, but given it uses an empty slot inside a Transition it seems quite similar:

@edison1105 edison1105 changed the title fix(hydration): handle empty content in Transition appear edge case fix(hydration): handle empty content in Transition hydration edge case Jun 4, 2025
@edison1105 edison1105 force-pushed the edison/fix/13394 branch 2 times, most recently from 3983741 to a6d8b6e Compare June 4, 2025 06:44
@edison1105
Copy link
Member Author

/ecosystem-ci run

@edison1105 edison1105 changed the title fix(hydration): handle empty content in Transition hydration edge case fix(ssr): ensure empty slots render as comment node in Transition Jun 4, 2025
@vue-bot
Copy link
Contributor
vue-bot commented Jun 4, 2025

📝 Ran ecosystem CI: Open

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

@edison1105
Copy link
Member Author
edison1105 commented Jun 4, 2025

@skirtles-code
I've updated the code.

The underlying problem is that the CSR renders a comment vnode but the server output has nothing. with this PR, the SSR renders a comment node for an empty Transition to avoid hydration mismatch.

I think there is no need to fix the following invalid usage

@skirtles-code
Copy link
Contributor

What do you think about this case, with the Transition wrapped in a component?

@edison1105
Copy link
Member Author

What do you think about this case, with the Transition wrapped in a component?

Updated.

@edison1105 edison1105 changed the title fix(ssr): ensure empty slots render as comment node in Transition fix(ssr): ensure empty slots render as a comment node in Transition Jun 5, 2025
@skirtles-code
Copy link
Contributor

There still seems to be a problem when the parent uses a render function:

The original issue came from some code on Vue Land, which was using a render function like this.

For the slot I'm using () => null, but () => [] also fails. The original code had some conditional logic in the slot, but in practice it ended up returning null.

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:hydration scope: transition
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SSR hydration fails with <Transition appear> and empty content
3 participants
0