Skip to content

fix ssr warning - #5

Open
ichn-hu wants to merge 1 commit into
Cusdis:masterfrom
ichn-hu:fix-ssr
Open

fix ssr warning#5
ichn-hu wants to merge 1 commit into
Cusdis:masterfrom
ichn-hu:fix-ssr

Conversation

@ichn-hu

@ichn-hu ichn-hu commented Oct 26, 2021

Copy link
Copy Markdown

@ichn-hu

ichn-hu commented Oct 26, 2021

Copy link
Copy Markdown
Author

@djyde PTAL~

@AmagiDDmxh

AmagiDDmxh commented Oct 27, 2021

Copy link
Copy Markdown

我觉得可以考虑把 SSR 相关的都写到一个地方,像 layoutEffect / effect 常见的就是 useIsoMorphicEffect

参考:https://github.com/tailwindlabs/headlessui/blob/main/packages/%40headlessui-react/src/hooks/use-iso-morphic-effect.ts

定义一个 constant isServer 然后复用,如 https://github.com/benawad/dogehouse/blob/staging/kibbeh/src/lib/isServer.ts

Chakra 的解决方案:https://github.com/chakra-ui/chakra-ui/blob/main/packages/utils/src/dom.ts#L35-L43

@djyde

djyde commented Oct 28, 2021

Copy link
Copy Markdown
Contributor

Would it cause "window is not defined" when rendering in server side?

@AmagiDDmxh

AmagiDDmxh commented Oct 28, 2021

Copy link
Copy Markdown

well, try typeof undefined === 'undefined' or typeof undefinedVarable is pretty fine in JS, everything starts with undefined

@jukrb0x

jukrb0x commented May 11, 2023

Copy link
Copy Markdown

why not just use hybrid rendering approach, make the cusdis to be rendered in the web browser instead of ssr.

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

Successfully merging this pull request may close these issues.

Nextjs SSR prints warning on useLayoutEffect

4 participants