File tree Expand file tree Collapse file tree
apps/qwikrouter-test/src/routes/(common)/issue2644 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- export const data : string [ ] = [ ] ;
1+ // Per-session storage so the mpa and spa Playwright describe blocks (and any
2+ // other parallel workers) don't race on a shared module-level array.
3+ // The session id is carried in a cookie set by the root action.
4+ const sessionData = new Map < string , string [ ] > ( ) ;
5+
6+ export const SESSION_COOKIE = 'issue2644-session' ;
7+
8+ export const getSessionData = ( sessionId : string | undefined ) : string [ ] => {
9+ if ( ! sessionId ) {
10+ return [ ] ;
11+ }
12+ let data = sessionData . get ( sessionId ) ;
13+ if ( ! data ) {
14+ data = [ ] ;
15+ sessionData . set ( sessionId , data ) ;
16+ }
17+ return data ;
18+ } ;
19+
20+ export const createSessionId = ( ) =>
21+ `s-${ Date . now ( ) . toString ( 36 ) } -${ Math . random ( ) . toString ( 36 ) . slice ( 2 , 10 ) } ` ;
Original file line number Diff line number Diff line change 11import { component$ } from '@qwik.dev/core' ;
22import { Form , routeAction$ } from '@qwik.dev/router' ;
3- import { data } from './data' ;
3+ import { SESSION_COOKIE , createSessionId , getSessionData } from './data' ;
44
55export const useRootAction = routeAction$ (
6- ( form , { redirect } ) => {
7- const name = form . name as string ;
6+ ( form , { redirect, cookie } ) => {
7+ let sessionId = cookie . get ( SESSION_COOKIE ) ?. value ;
8+ if ( ! sessionId ) {
9+ sessionId = createSessionId ( ) ;
10+ cookie . set ( SESSION_COOKIE , sessionId , { path : '/' } ) ;
11+ }
12+ const data = getSessionData ( sessionId ) ;
813 data . length = 0 ;
9- data . push ( name ) ;
14+ data . push ( form . name as string ) ;
1015 throw redirect ( 303 , '/qwikrouter-test/issue2644/other/' ) ;
1116 } ,
1217 {
Original file line number Diff line number Diff line change 11import { Form , routeAction$ , routeLoader$ } from '@qwik.dev/router' ;
22import { component$ } from '@qwik.dev/core' ;
3- import { data } from '../data' ;
3+ import { SESSION_COOKIE , getSessionData } from '../data' ;
44
5- export const useGetData = routeLoader$ ( ( ) => {
6- return data ;
5+ export const useGetData = routeLoader$ ( ( { cookie } ) => {
6+ return getSessionData ( cookie . get ( SESSION_COOKIE ) ?. value ) ;
77} ) ;
88
9- export const useOtherAction = routeAction$ ( ( form ) => {
9+ export const useOtherAction = routeAction$ ( ( form , { cookie } ) => {
10+ const data = getSessionData ( cookie . get ( SESSION_COOKIE ) ?. value ) ;
1011 const name = form . name as string ;
1112 data . push ( name ) ;
1213 return { success : true } ;
Original file line number Diff line number Diff line change @@ -11,7 +11,9 @@ test('rendered', async ({ page }) => {
1111
1212 const state = page . locator ( '#state' ) ;
1313
14- await expect ( state ) . toHaveText ( 'finished' ) ;
14+ // Partytown spins up a web worker to run the simulated async work; under parallel
15+ // test load the worker init can take well over the default 3s expect timeout.
16+ await expect ( state ) . toHaveText ( 'finished' , { timeout : 15000 } ) ;
1517} ) ;
1618
1719test ( 'update text' , async ( { page } ) => {
You can’t perform that action at this time.
0 commit comments