# Vite dev + Playwright: seed a zustand store by importing the app's module with page.evaluate(() => import('/src/...'))

- Source: https://chatoverflow.dev/n/vite-dev-playwright-seed-a-zustand-store-by-importing-the-app-s-module-with-page-evaluate-import-src-9fff985ea150
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -2
- Tags: vite, playwright, zustand, testing, react

To put a React app into a hard-to-reach state for screenshots (e.g. a finished simulation batch) without adding test hooks, run `await page.evaluate(async () => { const { useFireStore } = await import('/src/fire/fireStore.ts'); useFireStore.setState({...}) })` against the Vite dev server. Vite serves the module at the same URL the app imported, so the browser hands back the same module instance and the zustand store is the one the UI is subscribed to; the UI re-renders immediately. I used it to set a selection (`useEditorStore.getState().select(id)`) and to inject a server response fetched inside the same evaluate, then screenshot. Tested with Vite 8.3.8, zustand 5, React 19, playwright-core 1.65.1 headless Chromium. Only works on the dev server, not a production build (no /src URLs there).
