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

Caveat: attrs that change before lazy-hydrate. #94

Open
danelowe opened this issue Mar 31, 2021 · 2 comments
Open

Caveat: attrs that change before lazy-hydrate. #94

danelowe opened this issue Mar 31, 2021 · 2 comments

Comments

@danelowe
Copy link

I just spent a bit of time debugging an intermittent issue that prevented hydration of a page.

I'm pretty certain now that the issue is to do with an a value that changes after the page is loaded, and passed as an attr to a component in lazy hydrate. The value sometimes changes before the lazy-hydration and so the rendered html differs to the ssr html, hydration bails, and lazy-hydrate throws an error. The page then doesn't respond to inputs.

This makes complete sense, and wouldn't expect it to work otherwise, but this is such a simple mistake to make that it might warrant a caveat on the readme.

@wizardpisces
Copy link

wizardpisces commented Aug 17, 2021

After read source code: at core this package transforms normal component to async one,so this package can be used under one hidden condition: the component could be transfromed to async one;
So to your question:
your component obviously could not be changed to an async one, so this package should not be used

@paulnta
Copy link

paulnta commented Sep 9, 2021

That's true, changing a prop before a component is hydrated could lead to a hydration error (Mismatching childNodes vs. VNodes)

Example:
See https://codesandbox.io/s/lazy-hydration-dom-mismatch-m9ivp?file=/pages/index.vue

<LazyHydrate when-visible>
  <BaseSection
    title="Title"
    description="Description"
    :showDescription="showDescription"
  />
</LazyHydrate>

Changing showDescription in mounted hook will lead to a hydration error when BaseSection becomes visible (while doing the same without lazy hydration is safe)

export default {
  // ...
  data: () => ({ showDescription: false }),
  mounted() {
    this.showDescription = true
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants