mirror of
https://github.com/alibaba/ice.git
synced 2024-10-23 07:04:52 +08:00
feat: support suspence event (#6975)
* feat: support suspence event * feat: support suspense script id
This commit is contained in:
parent
61d7c95d30
commit
9c3d9c583e
5
.changeset/seven-mails-tickle.md
Normal file
5
.changeset/seven-mails-tickle.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'@ice/runtime': patch
|
||||
---
|
||||
|
||||
feat: support suspense event
|
@ -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>
|
||||
|
@ -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>
|
||||
);
|
||||
@ -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)}}();` }} />
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user