@@ -12,141 +12,144 @@ import { type TemplateName, reactRouterConfig } from "./helpers/vite.js";
12
12
13
13
const templateNames = [
14
14
"vite-5-template" ,
15
- "rsc-parcel -framework" ,
15
+ "rsc-vite -framework" ,
16
16
] as const satisfies TemplateName [ ] ;
17
17
18
- function getFiles ( {
19
- splitRouteModules,
20
- parentClientLoader,
21
- parentClientLoaderHydrate,
22
- parentAdditions,
23
- childClientLoader,
24
- childClientLoaderHydrate,
25
- childAdditions,
26
- } : {
27
- splitRouteModules : boolean ;
28
- parentClientLoader : boolean ;
29
- parentClientLoaderHydrate : boolean ;
30
- parentAdditions ?: string ;
31
- childClientLoader : boolean ;
32
- childClientLoaderHydrate : boolean ;
33
- childAdditions ?: string ;
34
- } ) {
35
- return {
36
- "react-router.config.ts" : reactRouterConfig ( { splitRouteModules } ) ,
37
- "app/root.tsx" : js `
38
- import { Outlet, Scripts } from "react-router"
39
-
40
- export default function Root() {
41
- return (
42
- <html>
43
- <head></head>
44
- <body>
45
- <main>
46
- <Outlet />
47
- </main>
48
- <Scripts />
49
- </body>
50
- </html>
51
- );
52
- }
53
- ` ,
54
- "app/routes/_index.tsx" : js `
55
- import { Link } from "react-router"
56
- export default function Component() {
57
- return <Link to="/parent/child">Go to /parent/child</Link>
58
- }
59
- ` ,
60
- "app/routes/parent.tsx" : js `
61
- import { Outlet, useLoaderData } from "react-router"
62
- export function loader() {
63
- return { message: 'Parent Server Loader' };
64
- }
65
- ${
66
- parentClientLoader
67
- ? js `
68
- export async function clientLoader({ serverLoader }) {
69
- // Need a small delay to ensure we capture the server-rendered
70
- // fallbacks for assertions
71
- await new Promise(r => setTimeout(r, 100))
72
- let data = await serverLoader();
73
- return { message: data.message + " (mutated by client)" };
74
- }
75
- `
76
- : ""
77
- }
78
- ${
79
- parentClientLoaderHydrate
80
- ? js `
81
- clientLoader.hydrate = true;
82
- export function HydrateFallback() {
83
- return <p>Parent Fallback</p>
84
- }
85
- `
86
- : ""
87
- }
88
- ${ parentAdditions || "" }
89
- export default function Component() {
90
- let data = useLoaderData();
91
- return (
92
- <>
93
- <p id="parent-data">{data.message}</p>
94
- <Outlet/>
95
- </>
96
- );
97
- }
98
- ` ,
99
- "app/routes/parent.child.tsx" : js `
100
- import { Form, Outlet, useActionData, useLoaderData } from "react-router"
101
- export function loader() {
102
- return { message: 'Child Server Loader' };
103
- }
104
- export function action() {
105
- return { message: 'Child Server Action' };
106
- }
107
- ${
108
- childClientLoader
109
- ? js `
110
- export async function clientLoader({ serverLoader }) {
111
- // Need a small delay to ensure we capture the server-rendered
112
- // fallbacks for assertions
113
- await new Promise(r => setTimeout(r, 100))
114
- let data = await serverLoader();
115
- return { message: data.message + " (mutated by client)" };
116
- }
117
- `
118
- : ""
119
- }
120
- ${
121
- childClientLoaderHydrate
122
- ? js `
123
- clientLoader.hydrate = true;
124
- export function HydrateFallback() {
125
- return <p>Child Fallback</p>
126
- }
127
- `
128
- : ""
129
- }
130
- ${ childAdditions || "" }
131
- export default function Component() {
132
- let data = useLoaderData();
133
- let actionData = useActionData();
134
- return (
135
- <>
136
- <p id="child-data">{data.message}</p>
137
- <Form method="post">
138
- <button type="submit">Submit</button>
139
- {actionData ? <p id="child-action-data">{actionData.message}</p> : null}
140
- </Form>
141
- </>
142
- );
143
- }
144
- ` ,
145
- } ;
146
- }
147
-
148
18
test . describe ( "Client Data" , ( ) => {
149
19
for ( const templateName of templateNames ) {
20
+ function getFiles ( {
21
+ splitRouteModules,
22
+ parentClientLoader,
23
+ parentClientLoaderHydrate,
24
+ parentAdditions,
25
+ childClientLoader,
26
+ childClientLoaderHydrate,
27
+ childAdditions,
28
+ } : {
29
+ splitRouteModules : boolean ;
30
+ parentClientLoader : boolean ;
31
+ parentClientLoaderHydrate : boolean ;
32
+ parentAdditions ?: string ;
33
+ childClientLoader : boolean ;
34
+ childClientLoaderHydrate : boolean ;
35
+ childAdditions ?: string ;
36
+ } ) {
37
+ return {
38
+ "react-router.config.ts" : reactRouterConfig ( {
39
+ splitRouteModules,
40
+ viteEnvironmentApi : templateName . includes ( "rsc" ) ,
41
+ } ) ,
42
+ "app/root.tsx" : js `
43
+ import { Outlet, Scripts } from "react-router"
44
+
45
+ export default function Root() {
46
+ return (
47
+ <html>
48
+ <head></head>
49
+ <body>
50
+ <main>
51
+ <Outlet />
52
+ </main>
53
+ <Scripts />
54
+ </body>
55
+ </html>
56
+ );
57
+ }
58
+ ` ,
59
+ "app/routes/_index.tsx" : js `
60
+ import { Link } from "react-router"
61
+ export default function Component() {
62
+ return <Link to="/parent/child">Go to /parent/child</Link>
63
+ }
64
+ ` ,
65
+ "app/routes/parent.tsx" : js `
66
+ import { Outlet, useLoaderData } from "react-router"
67
+ export function loader() {
68
+ return { message: 'Parent Server Loader' };
69
+ }
70
+ ${
71
+ parentClientLoader
72
+ ? js `
73
+ export async function clientLoader({ serverLoader }) {
74
+ // Need a small delay to ensure we capture the server-rendered
75
+ // fallbacks for assertions
76
+ await new Promise(r => setTimeout(r, 100))
77
+ let data = await serverLoader();
78
+ return { message: data.message + " (mutated by client)" };
79
+ }
80
+ `
81
+ : ""
82
+ }
83
+ ${
84
+ parentClientLoaderHydrate
85
+ ? js `
86
+ clientLoader.hydrate = true;
87
+ export function HydrateFallback() {
88
+ return <p>Parent Fallback</p>
89
+ }
90
+ `
91
+ : ""
92
+ }
93
+ ${ parentAdditions || "" }
94
+ export default function Component() {
95
+ let data = useLoaderData();
96
+ return (
97
+ <>
98
+ <p id="parent-data">{data.message}</p>
99
+ <Outlet/>
100
+ </>
101
+ );
102
+ }
103
+ ` ,
104
+ "app/routes/parent.child.tsx" : js `
105
+ import { Form, Outlet, useActionData, useLoaderData } from "react-router"
106
+ export function loader() {
107
+ return { message: 'Child Server Loader' };
108
+ }
109
+ export function action() {
110
+ return { message: 'Child Server Action' };
111
+ }
112
+ ${
113
+ childClientLoader
114
+ ? js `
115
+ export async function clientLoader({ serverLoader }) {
116
+ // Need a small delay to ensure we capture the server-rendered
117
+ // fallbacks for assertions
118
+ await new Promise(r => setTimeout(r, 100))
119
+ let data = await serverLoader();
120
+ return { message: data.message + " (mutated by client)" };
121
+ }
122
+ `
123
+ : ""
124
+ }
125
+ ${
126
+ childClientLoaderHydrate
127
+ ? js `
128
+ clientLoader.hydrate = true;
129
+ export function HydrateFallback() {
130
+ return <p>Child Fallback</p>
131
+ }
132
+ `
133
+ : ""
134
+ }
135
+ ${ childAdditions || "" }
136
+ export default function Component() {
137
+ let data = useLoaderData();
138
+ let actionData = useActionData();
139
+ return (
140
+ <>
141
+ <p id="child-data">{data.message}</p>
142
+ <Form method="post">
143
+ <button type="submit">Submit</button>
144
+ {actionData ? <p id="child-action-data">{actionData.message}</p> : null}
145
+ </Form>
146
+ </>
147
+ );
148
+ }
149
+ ` ,
150
+ } ;
151
+ }
152
+
150
153
let appFixture : AppFixture ;
151
154
152
155
test . afterEach ( async ( ) => {
0 commit comments