recoil-persist icon indicating copy to clipboard operation
recoil-persist copied to clipboard

persistAtom error on initialLoad

Open deshario opened this issue 3 years ago • 3 comments

Did not expect server HTML to contain a <span> in <div>.

persistAtom will create an error as above on initial load. which will effects on layout to be broken a little ... Is there anything that missing from me to prevent this problem ?

** Atoms **

export const keySecret = atom({
  key: "keySecret",
  default: {
    mKey : '',
    mSecret : ''
  },
  effects_UNSTABLE: [persistAtom] // Problem
})
** _app.tsx **

<>
  <Head>
    <title>Title</title>
  </Head>
  <ApolloProvider client={apolloClient}>
    <RecoilRoot>
      <RootLayout {...pageProps}>
        <Component {...pageProps} />
      </RootLayout>
    </RecoilRoot>
  </ApolloProvider>
</>
** Dependencies **

"next": "^11.1.0",
"antd": "4.15.6",
"recoil-persist": "^3.0.0",

Screen Shot 2564-08-23 at 09 32 28

deshario avatar Aug 23 '21 02:08 deshario

Same here. It happens when server and client produce difference HTML because you conditionally display element by recoil state from local storage but server has no idea about local storage.

@deshario Did you find workaround for this?

rutcreate avatar Dec 20 '21 07:12 rutcreate

Any update?

muqshots avatar Dec 27 '21 22:12 muqshots

I had the same problem and eventually found a workaround here: https://stackoverflow.com/a/70459889/12298350

Maxe12 avatar Jan 19 '22 09:01 Maxe12