mirror of https://github.com/alibaba/ice.git
Compare commits
7 Commits
3860b789f4
...
1f9030aefa
| Author | SHA1 | Date |
|---|---|---|
|
|
1f9030aefa | |
|
|
d55e34bc56 | |
|
|
b2d93c6ffe | |
|
|
72bfa88d17 | |
|
|
9b95b4c031 | |
|
|
22d1b49c9c | |
|
|
4569200caf |
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@ice/runtime': patch
|
||||
---
|
||||
|
||||
feat: add suspense event dispatch in Suspense component
|
||||
|
|
@ -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
|
||||
/>
|
||||
);
|
||||
}
|
||||
Loading…
Reference in New Issue