Skip to content
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

encounter " Hydration node mismatch" when using keep-alive in ssr rendering #4817

Closed
tcstory opened this issue Oct 19, 2021 · 7 comments
Closed
Labels
❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. 🐞 bug Something isn't working scope: ssr

Comments

@tcstory
Copy link

tcstory commented Oct 19, 2021

Version

3.2.20

Reproduction link

github.com

Steps to reproduce

first, change the App.vue file to the following( replace <Suspense> with <keep-alive>)

<template>
  <div>
    <router-link to="/">Home</router-link>|
    <router-link to="/about">About</router-link>
    <router-view v-slot="{ Component }">
      <keep-alive>
        <component :is="Component" />
      </keep-alive>
    </router-view>
  </div>
</template>

second, run pnpm run dev
third, access http://localhost:3000/

and you will see the error in console panel.

What is expected?

no error is reported

What is actually happening?

there is a error


even though the reproduction project is using vite, the error is still there when you using webpack.

@tcstory
Copy link
Author

tcstory commented Oct 19, 2021

there is a screenshot
image

@ovidiuc
Copy link

ovidiuc commented Nov 16, 2021

I'm having the same problem, using Quasar framework. The component rendered by <router-view> server side is wrapped in a <!--[--> <!--]--> that the client is not expecting.

@mekery

This comment has been minimized.

@DoubleJ-G
Copy link

I am also noticing something similar also happen with the fragment comments

- Client vnode: div 
- Server rendered DOM: <!--[--> (start of fragment)

Nothing actually seems to be mismatched besides these comments. From what I can tell they are used for v-for and , possibly also for components with more than 1 root element.

@gfordinal
Copy link

Same problem here.
Seems to appear on v-for and dynamic components <component :is="" />

@tcstory Could you find a solution?

@semirbabajic
Copy link

Was anyone able to find a solution for this? Have the same problem using Quasar 2.5.4 @tcstory

@posva posva added the ❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. label Feb 10, 2022
@mefcorvi
Copy link
Contributor

It seems that the server-side rendering code

if (!sharedContext.renderer) {
return slots.default
}
does not match the client-side rendering logic and it should be rewritten like this:

  if (!sharedContext.renderer) {
    return () => {
      if (!slots.default) {
        return null;
      }

      const children = slots.default();
      if (children.length > 1) {
        warn(`KeepAlive should contain exactly one component child.`);
        return children;
      }

      return children[0];
  }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. 🐞 bug Something isn't working scope: ssr
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants