authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-09-05 01:53:19-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-09-05 01:53:19-07:00
log43700b83e73fca3af7b63769876c409b5c6f5a3f
tree870ed159eabc11d0f22ee69c649292f47221c9e0
parent160e337a5c521bcaae94b386d22226f32242fdd0
signature Signed by PGP key B5690EEEBB952194

refactor(web): observe preview tests through the live registry (#10064)


2 files changed, 2 insertions(+), 15 deletions(-)

apps/web/src/previewStateStore.test.ts+2-2
......@@ -19,10 +19,10 @@ import {
1919 reconcilePreviewServerSessions,
2020 rememberPreviewUrl,
2121 resetPreviewStateForTests,
22 subscribeThreadPreviewState,
2322 setActivePreviewTab,
2423 updatePreviewServerSnapshot,
2524} from "./previewStateStore";
25import { appAtomRegistry } from "./rpc/atomRegistry";
2626
2727const environmentId = "env-1" as EnvironmentId;
2828const ref = scopeThreadRef(environmentId, ThreadId.make("thread-1"));
......@@ -352,7 +352,7 @@ describe("previewStateStore (single-tab)", () => {
352352 },
353353 };
354354 let updateCount = 0;
355 const unsubscribe = subscribeThreadPreviewState(ref, () => {
355 const unsubscribe = appAtomRegistry.subscribe(previewStateAtom(scopedThreadKey(ref)), () => {
356356 updateCount += 1;
357357 });
358358
apps/web/src/previewStateStore.ts-13
......@@ -173,19 +173,6 @@ export function readThreadPreviewState(ref: ScopedThreadRef): ThreadPreviewState
173173 return appAtomRegistry.get(previewStateAtom(scopedThreadKey(ref)));
174174}
175175
176export function subscribeThreadPreviewState(
177 ref: ScopedThreadRef,
178 listener: (state: ThreadPreviewState, previous: ThreadPreviewState) => void,
179): () => void {
180 const atom = previewStateAtom(scopedThreadKey(ref));
181 let previous = appAtomRegistry.get(atom);
182 return appAtomRegistry.subscribe(atom, (state) => {
183 const prior = previous;
184 previous = state;
185 listener(state, prior);
186 });
187}
188
189176export function applyPreviewServerEvent(ref: ScopedThreadRef, event: PreviewEvent): void {
190177 updateThreadPreviewState(ref, (current) => {
191178 if (current.serverEpoch !== null && event.serverEpoch !== current.serverEpoch) return current;