Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/legal-zebras-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/react": patch
---

Create element without ref for suspense in main thread.
38 changes: 23 additions & 15 deletions packages/react/runtime/src/lynx/suspense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,33 @@ export const Suspense: FunctionComponent<{ children: VNode | VNode[]; fallback:
(__MAIN_THREAD__ ? createElementMainThread : createElementBackground) as typeof createElementBackground;
const childrenRef = useRef<BackgroundSnapshotInstance>();

const newChildren = __createElement('wrapper', {
ref: (bsi: BackgroundSnapshotInstance) => {
if (bsi) {
childrenRef.current = bsi;
}
const newChildren = __createElement(
'wrapper',
__MAIN_THREAD__ ? {} : {
ref: (bsi: BackgroundSnapshotInstance) => {
if (bsi) {
childrenRef.current = bsi;
}
},
},
}, children);
children,
);

const newFallback = __createElement('wrapper', {
ref: (bsi: BackgroundSnapshotInstance) => {
if (bsi && childrenRef.current) {
const i = globalBackgroundSnapshotInstancesToRemove.indexOf(childrenRef.current.__id);
if (i !== -1) {
globalBackgroundSnapshotInstancesToRemove.splice(i, 1);
const newFallback = __createElement(
'wrapper',
__MAIN_THREAD__ ? {} : {
ref: (bsi: BackgroundSnapshotInstance) => {
if (bsi && childrenRef.current) {
const i = globalBackgroundSnapshotInstancesToRemove.indexOf(childrenRef.current.__id);
if (i !== -1) {
globalBackgroundSnapshotInstancesToRemove.splice(i, 1);
}
childrenRef.current = undefined;
}
childrenRef.current = undefined;
}
},
},
}, fallback);
fallback,
);

return __createElement(PreactSuspense, { fallback: newFallback }, newChildren);
};
Loading