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

SSR - Hydration text mismatch #209

Open
imcm7 opened this issue Sep 12, 2023 · 5 comments
Open

SSR - Hydration text mismatch #209

imcm7 opened this issue Sep 12, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@imcm7
Copy link

imcm7 commented Sep 12, 2023

On server it not read color because color is stored in local storage and not cookie

@imcm7 imcm7 added the bug Something isn't working label Sep 12, 2023
@RamaHerbin
Copy link

I've got the same issue here
Screenshot 2023-10-16 at 14 53 42

@Kolobok12309
Copy link

You can try use ClientOnly for components that use theme variable like this

<div class="color-theme-switcher">
  <ClientOnly>
    <SfIcon
      :icon="iconName"
      class="color-theme-switcher__icon"
    />
  
    <span class="color-theme-switcher__text">
      Theme
    </span>
  
    <SfToggleSwitch
      v-model="isDark"
      class="color-theme-switcher__toggler"
    />
  
    <template #placeholder>
      <div class="color-theme-switcher__placeholder" />
    </template>
  </ClientOnly>
</div>

@TsotMe
Copy link

TsotMe commented Jul 28, 2024

@Kolobok12309 Then on page refresh that content inside ClientOnly will disappear until client render

You can try use ClientOnly for components that use theme variable like this

<div class="color-theme-switcher">
  <ClientOnly>
    <SfIcon
      :icon="iconName"
      class="color-theme-switcher__icon"
    />
  
    <span class="color-theme-switcher__text">
      Theme
    </span>
  
    <SfToggleSwitch
      v-model="isDark"
      class="color-theme-switcher__toggler"
    />
  
    <template #placeholder>
      <div class="color-theme-switcher__placeholder" />
    </template>
  </ClientOnly>
</div>

@Kolobok12309
Copy link

@TsotMe Most powerful way is to use cookie and http header for ssr, and if both of them missing, use ClientOnly. Fulfillment without ClientOnly you can try use css( but I don't like css for this cases), or you get flashes between render and mount

@sharifzadesina
Copy link

sharifzadesina commented Sep 14, 2024

It seems cookie storage is merged but this issue is not fixed.
The interesting thing is, when I use <img :src="/img/logo-${colorMode.value}.svg">, src attribute doesn't update after mount.
Because colorMode.value only changes to real value after mount but the attribute doesn't get updated.
I get a lot of mismatch errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants