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/fast-bears-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/react": patch
---

Avoid DEV_ONLY_SetSnapshotEntryName on standalone lazy bundle.
9 changes: 7 additions & 2 deletions packages/react/runtime/__test__/snapshotPatch.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1609,13 +1609,14 @@ describe('lazy snapshot', () => {
const si = new SnapshotInstance(uniqueId);
expect(si.type).toBe('https://example.com/main.lynx.bundle:snapshot-1');
});
it('standalone lazy bundle snapshotCreatorMap set should not generate DEV_ONLY_AddSnapshot', () => {
it('standalone lazy bundle snapshotCreatorMap set should not generate DEV_ONLY_AddSnapshot and DEV_ONLY_SetSnapshotEntryName', () => {
initGlobalSnapshotPatch();
expect(__globalSnapshotPatch).toMatchInlineSnapshot(`[]`);

const globDynamicComponentEntry = 'https://example.com/main.lynx.bundle';
const uniqID = `${globDynamicComponentEntry}:${'__snapshot_835da_eff1e_1'}`;

snapshotCreatorMap[`${globDynamicComponentEntry}:${'__snapshot_835da_eff1e_1'}`] = (uniqID) => {
snapshotCreatorMap[uniqID] = (uniqID) => {
globalThis.createSnapshot(
uniqID,
/* v8 ignore start */
Expand All @@ -1636,6 +1637,10 @@ describe('lazy snapshot', () => {

expect(__globalSnapshotPatch.length).toBe(0);

vi.stubGlobal('__JS__', true);
snapshotCreatorMap[uniqID](uniqID);
expect(__globalSnapshotPatch.length).toBe(0);

deinitGlobalSnapshotPatch();
expect(__globalSnapshotPatch).toMatchInlineSnapshot(`undefined`);
});
Expand Down
6 changes: 5 additions & 1 deletion packages/react/runtime/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,11 @@ export function createSnapshot(
}
// For Lazy Bundle, their entryName is not DEFAULT_ENTRY_NAME.
// We need to set the entryName correctly for HMR
if (__DEV__ && __JS__ && __globalSnapshotPatch && entryName && entryName !== DEFAULT_ENTRY_NAME) {
if (
__DEV__ && __JS__ && __globalSnapshotPatch && entryName && entryName !== DEFAULT_ENTRY_NAME
// `uniqID` will be `https://example.com/main.lynx.bundle:__snapshot_835da_eff1e_1` when loading a standalone lazy bundle after hydration.
&& !uniqID.includes(':')
) {
__globalSnapshotPatch.push(
SnapshotOperation.DEV_ONLY_SetSnapshotEntryName,
uniqID,
Expand Down
Loading