diff --git a/.changeset/lazy-cups-cross.md b/.changeset/lazy-cups-cross.md new file mode 100644 index 0000000000..6eaacbf324 --- /dev/null +++ b/.changeset/lazy-cups-cross.md @@ -0,0 +1,5 @@ +--- +'@ice/plugin-stream-error': patch +--- + +fix: refactor load event handling for SSR re-rendering in plugin-stream-error diff --git a/packages/plugin-stream-error/src/index.tsx b/packages/plugin-stream-error/src/index.tsx index e6dc42d937..eaeec23714 100644 --- a/packages/plugin-stream-error/src/index.tsx +++ b/packages/plugin-stream-error/src/index.tsx @@ -17,7 +17,7 @@ const plugin: Plugin = (options = { generator.addEntryCode((originalCode) => { return `${originalCode} if (import.meta.renderer === 'client') { - window.addEventListener('load', (event) => { + function froceRerender() { // _$ServerTimePoints will returned at the end of last stream, // if the value is undefined, try to re-render app with CSR. if (${activeInDev ? '' : 'process.env.NODE_ENV === \'production\' && '}!window._$ServerTimePoints && window.__ICE_APP_CONTEXT__.renderMode === 'SSR') { @@ -28,7 +28,12 @@ if (import.meta.renderer === 'client') { window.__ICE_APP_CONTEXT__.renderMode = 'CSR'; render({ hydrate: false }); } - }); + } + if (document.readyState === 'complete') { + froceRerender(); + } else { + window.addEventListener('load', froceRerender); + } }`; }); }