Skip to content

Commit 6b3871a

Browse files
test(solid): cover async client store hydration
Co-authored-by: Cursor <[email protected]>
1 parent a7c6b8e commit 6b3871a

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

‎packages/solid/test/client-hydration.spec.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,57 @@ describe("bare ssrSource 'client' — unasked through the gate, computes after",
12421242
flush();
12431243
expect(store.name).toBe("computed");
12441244
});
1245+
1246+
test("createStore(fn) keeps Loading fallback through the first client flight", async () => {
1247+
startHydration({});
1248+
const read = (value: any): any => {
1249+
while (typeof value === "function") value = value();
1250+
return value;
1251+
};
1252+
1253+
let store: any;
1254+
let result: any;
1255+
let deriveRan = 0;
1256+
let resolveDerive!: (value: { name: string }) => void;
1257+
createRoot(
1258+
() => {
1259+
[store] = createStore<{ name: string }>(
1260+
() => {
1261+
deriveRan++;
1262+
return new Promise(resolve => (resolveDerive = resolve));
1263+
},
1264+
{ name: "seed" },
1265+
{ ssrSource: "client" }
1266+
);
1267+
result = Loading({
1268+
fallback: "loading" as any,
1269+
get children() {
1270+
return store.name;
1271+
}
1272+
});
1273+
},
1274+
{ id: "t" }
1275+
);
1276+
flush();
1277+
1278+
expect(deriveRan).toBe(0);
1279+
expect(() => store.name).toThrow(NotReadyError);
1280+
expect(read(result)).toBe("loading");
1281+
1282+
stopHydration();
1283+
flush();
1284+
1285+
expect(deriveRan).toBe(1);
1286+
expect(() => store.name).toThrow(NotReadyError);
1287+
expect(read(result)).toBe("loading");
1288+
1289+
resolveDerive({ name: "landed" });
1290+
await new Promise<void>(resolve => setTimeout(resolve));
1291+
flush();
1292+
1293+
expect(store.name).toBe("landed");
1294+
expect(read(result)).toBe("landed");
1295+
});
12451296
});
12461297

12471298
// The hydration gate must not close the loading window: a sync prev-return

0 commit comments

Comments
 (0)