Skip to content

Commit

Permalink
feat: support suspence event (#6975)
Browse files Browse the repository at this point in the history
* feat: support suspence event

* feat: support suspense script id
  • Loading branch information
answershuto authored Aug 30, 2024
1 parent 61d7c95 commit 9c3d9c5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/seven-mails-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ice/runtime': patch
---

feat: support suspense event
1 change: 1 addition & 0 deletions examples/with-suspense-ssr/src/document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function Document() {
</head>
<body>
<Main />
<script dangerouslySetInnerHTML={{ __html: 'window.addEventListener(\'suspense\', (d) => console.log(\'suspence event=\', d))' }} />
<Scripts async />
</body>
</html>
Expand Down
3 changes: 2 additions & 1 deletion packages/runtime/src/Suspense.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export function withSuspense(Component) {
<SuspenseContext.Provider value={suspenseState}>
<Component {...componentProps} />
<Data id={id} />
<script dangerouslySetInnerHTML={{ __html: `window.dispatchEvent(new CustomEvent('suspense', { detail: { id: '${id}' } }));` }} />
</SuspenseContext.Provider>
</React.Suspense>
);
Expand All @@ -166,6 +167,6 @@ function Data(props) {
const data = useSuspenseData();

return (
<script dangerouslySetInnerHTML={{ __html: `!function(){window['${LOADER}'] = window['${LOADER}'] || {};window['${LOADER}']['${props.id}'] = ${JSON.stringify(data)}}();` }} />
<script id={props.id ? `suspenseScript:${props.id}` : ''} dangerouslySetInnerHTML={{ __html: `!function(){window['${LOADER}'] = window['${LOADER}'] || {};window['${LOADER}']['${props.id}'] = ${JSON.stringify(data)}}();` }} />
);
}

0 comments on commit 9c3d9c5

Please sign in to comment.