feat(runtime): add custom event for suspense data updates (#7112)

* feat(runtime): add custom event for suspense data updates

* feat(runtime): remove ice-suspense custom event

* chore(runtime): add changeset
This commit is contained in:
Mixiu 2025-07-02 15:46:57 +08:00 committed by GitHub
parent 22b10c0d1c
commit 1a0a2c1f61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 6 deletions

View File

@ -0,0 +1,5 @@
---
'@ice/runtime': patch
---
feat: Add custom event for suspense data updates, and remove ice-suspense custom event.

View File

@ -156,11 +156,6 @@ export function withSuspense(Component) {
<SuspenseContext.Provider value={suspenseState}>
<Component {...componentProps} />
<Data id={id} />
<script
dangerouslySetInnerHTML={{
__html: `window.dispatchEvent(new CustomEvent('ice-suspense', { detail: { id: ${id ? `'${id}'` : undefined} } }));`,
}}
/>
</SuspenseContext.Provider>
</React.Suspense>
);
@ -174,7 +169,7 @@ function Data(props) {
<script
id={props.id && `suspense-script-${props.id}`}
dangerouslySetInnerHTML={{
__html: `!function(){window['${LOADER}'] = window['${LOADER}'] || {};window['${LOADER}']['${props.id}'] = ${JSON.stringify(data)}}();`,
__html: `!function(){window['${LOADER}'] = window['${LOADER}'] || {};window['${LOADER}']['${props.id}'] = ${JSON.stringify(data)}}();window.dispatchEvent(new CustomEvent('ice-suspense-data', { detail: { id: ${props.id ? `'${props.id}'` : undefined} } }));`,
}}
/>
);