Compare commits

...

7 Commits

Author SHA1 Message Date
ZeroLing 1f9030aefa
Merge f5005afad5 into d55e34bc56 2025-07-22 15:49:09 +08:00
Mixiu d55e34bc56
feat(runtime): add suspense event dispatch in Suspense component (#7122)
* feat(runtime): add suspense event dispatch in Suspense component

* chore(runtime): add changeset

* fix(runtime): Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix(runtime): optimize Suspense component script rendering

* fix(runtime): move dispatchSuspenseEvent function outside of withSuspense in Suspense.tsx

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-07-22 15:47:58 +08:00
ClarkXia b2d93c6ffe Merge branch 'master' into release/next 2025-07-14 10:37:03 +08:00
ClarkXia 72bfa88d17 chore: update version
Publish canary / Check Changeset exists (push) Has been cancelled Details
CI / build (16.x, ubuntu-latest) (push) Has been cancelled Details
CI / build (16.x, windows-latest) (push) Has been cancelled Details
CI / build (18.x, ubuntu-latest) (push) Has been cancelled Details
CI / build (18.x, windows-latest) (push) Has been cancelled Details
Version / Version (16) (push) Has been cancelled Details
Publish canary / Publish Canary (18) (push) Has been cancelled Details
2025-07-08 19:24:32 +08:00
ClarkXia 9b95b4c031 Merge branch 'master' into release/next 2025-07-08 19:19:02 +08:00
ClarkXia 22d1b49c9c chore: version 2025-07-08 19:15:34 +08:00
ClarkXia 4569200caf
feat: support externals field in assets-manifest (#7116)
Publish canary / Check Changeset exists (push) Waiting to run Details
Publish canary / Publish Canary (18) (push) Blocked by required conditions Details
CI / build (16.x, ubuntu-latest) (push) Waiting to run Details
CI / build (16.x, windows-latest) (push) Waiting to run Details
CI / build (18.x, ubuntu-latest) (push) Waiting to run Details
CI / build (18.x, windows-latest) (push) Waiting to run Details
Version / Version (16) (push) Waiting to run Details
2025-07-08 16:40:00 +08:00
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,5 @@
---
'@ice/runtime': patch
---
feat: add suspense event dispatch in Suspense component

View File

@ -126,6 +126,11 @@ interface SuspenseProps {
[key: string]: any;
}
function dispatchSuspenseEvent(event: string, id: string) {
window.dispatchEvent(new CustomEvent(event, { detail: { id } }));
}
const DISPATCH_SUSPENSE_EVENT_STRING = dispatchSuspenseEvent.toString();
export function withSuspense(Component) {
return (props: SuspenseProps) => {
const { fallback, id, ...componentProps } = props;
@ -153,10 +158,22 @@ export function withSuspense(Component) {
return (
<React.Suspense fallback={fallback || null}>
<InlineScript
id={`suspense-parse-start-${id}`}
script={`(${DISPATCH_SUSPENSE_EVENT_STRING})('ice-suspense-parse-start','${id}');`}
/>
<SuspenseContext.Provider value={suspenseState}>
<Component {...componentProps} />
<InlineScript
id={`suspense-parse-data-${id}`}
script={`(${DISPATCH_SUSPENSE_EVENT_STRING})('ice-suspense-parse-data','${id}');`}
/>
<Data id={id} />
</SuspenseContext.Provider>
<InlineScript
id={`suspense-parse-end-${id}`}
script={`(${DISPATCH_SUSPENSE_EVENT_STRING})('ice-suspense-parse-end','${id}');`}
/>
</React.Suspense>
);
};
@ -174,3 +191,20 @@ function Data(props) {
/>
);
}
interface InlineScriptProps {
id: string;
script: string;
}
function InlineScript(props: InlineScriptProps) {
return (
<script
id={props.id}
dangerouslySetInnerHTML={{
__html: props.script,
}}
suppressHydrationWarning
/>
);
}