From c44bd07fe7bfd288d60ecf2c92770b4ae26fad20 Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 28 May 2026 00:41:21 -0700 Subject: [PATCH] [eric] frontend: extend the store-on-window gate so an init-script flag also exposes it on production builds, letting e2e subscribe to redux diffs against the packaged app --- frontend/src/shared/state/store.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/frontend/src/shared/state/store.ts b/frontend/src/shared/state/store.ts index dffa7a6d..b4701ff1 100644 --- a/frontend/src/shared/state/store.ts +++ b/frontend/src/shared/state/store.ts @@ -58,9 +58,10 @@ export const store = configureStore({ export type RootState = ReturnType; export type AppDispatch = typeof store.dispatch; -// Expose the store on window in dev so playwright + the user's devtools -// can drive UI flows without hunting for selectors. The expose is -// guarded by NODE_ENV so production bundles don't ship it. -if (typeof window !== 'undefined' && process.env.NODE_ENV !== 'production') { +// Expose the store on window in dev. In production it stays hidden UNLESS the +// renderer was launched with __OPENSWARM_E2E__ pre-set by a Playwright init +// script, which is the only way the e2e visibility recorder can subscribe to +// state diffs against the packaged build. Normal user runs never set the flag. +if (typeof window !== 'undefined' && (process.env.NODE_ENV !== 'production' || (window as unknown as { __OPENSWARM_E2E__?: boolean }).__OPENSWARM_E2E__ === true)) { (window as unknown as { __OPENSWARM_STORE__?: typeof store }).__OPENSWARM_STORE__ = store; }