-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added SsrScript to work around suspended script (#99)
* simplified browser script * improved code structure * added ssr script
- Loading branch information
1 parent
02568ba
commit fd40498
Showing
4 changed files
with
60 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/stack/src/components/elements/ssr-layout-effect.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"use client"; | ||
import { useLayoutEffect } from "react"; | ||
|
||
export function SsrScript(props: { script: string }) { | ||
useLayoutEffect(() => { | ||
// TODO fix workaround: React has a bug where it doesn't run the script on the first CSR render if SSR has been skipped due to suspense | ||
// As a workaround, we run the script in the <script> tag again after the first render | ||
// Note that we do an indirect eval as described here: https://esbuild.github.io/content-types/#direct-eval | ||
(0, eval)(props.script); | ||
}, []); | ||
|
||
return <script dangerouslySetInnerHTML={{ __html: props.script }} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters