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 {...@@ -19,10 +19,10 @@ import {
19 reconcilePreviewServerSessions,19 reconcilePreviewServerSessions,
20 rememberPreviewUrl,20 rememberPreviewUrl,
21 resetPreviewStateForTests,21 resetPreviewStateForTests,
22 subscribeThreadPreviewState,
23 setActivePreviewTab,22 setActivePreviewTab,
24 updatePreviewServerSnapshot,23 updatePreviewServerSnapshot,
25} from "./previewStateStore";24} from "./previewStateStore";
25import { appAtomRegistry } from "./rpc/atomRegistry";
2626
27const environmentId = "env-1" as EnvironmentId;27const environmentId = "env-1" as EnvironmentId;
28const ref = scopeThreadRef(environmentId, ThreadId.make("thread-1"));28const ref = scopeThreadRef(environmentId, ThreadId.make("thread-1"));
...@@ -352,7 +352,7 @@ describe("previewStateStore (single-tab)", () => {...@@ -352,7 +352,7 @@ describe("previewStateStore (single-tab)", () => {
352 },352 },
353 };353 };
354 let updateCount = 0;354 let updateCount = 0;
355 const unsubscribe = subscribeThreadPreviewState(ref, () => {355 const unsubscribe = appAtomRegistry.subscribe(previewStateAtom(scopedThreadKey(ref)), () => {
356 updateCount += 1;356 updateCount += 1;
357 });357 });
358358
apps/web/src/previewStateStore.ts-13
...@@ -173,19 +173,6 @@ export function readThreadPreviewState(ref: ScopedThreadRef): ThreadPreviewState...@@ -173,19 +173,6 @@ export function readThreadPreviewState(ref: ScopedThreadRef): ThreadPreviewState
173 return appAtomRegistry.get(previewStateAtom(scopedThreadKey(ref)));173 return appAtomRegistry.get(previewStateAtom(scopedThreadKey(ref)));
174}174}
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
189export function applyPreviewServerEvent(ref: ScopedThreadRef, event: PreviewEvent): void {176export function applyPreviewServerEvent(ref: ScopedThreadRef, event: PreviewEvent): void {
190 updateThreadPreviewState(ref, (current) => {177 updateThreadPreviewState(ref, (current) => {
191 if (current.serverEpoch !== null && event.serverEpoch !== current.serverEpoch) return current;178 if (current.serverEpoch !== null && event.serverEpoch !== current.serverEpoch) return current;