@@ -2,7 +2,7 @@ import "@testing-library/jest-dom";
2
2
import { act , render , screen , waitFor } from "@testing-library/react" ;
3
3
import * as React from "react" ;
4
4
import type { LoaderFunction } from "react-router" ;
5
- import { RouterProvider as ReactRouter_RouterPRovider } from "react-router" ;
5
+ import { RouterProvider as ReactRouter_RouterProvider } from "react-router" ;
6
6
import {
7
7
Outlet ,
8
8
RouterProvider as ReactRouterDom_RouterProvider ,
@@ -28,7 +28,181 @@ describe("v7_partialHydration", () => {
28
28
} ) ;
29
29
30
30
describe ( "createMemoryRouter" , ( ) => {
31
- testPartialHydration ( createMemoryRouter , ReactRouter_RouterPRovider ) ;
31
+ testPartialHydration ( createMemoryRouter , ReactRouter_RouterProvider ) ;
32
+
33
+ // these tests only run for memory since we just need to set initialEntries
34
+ it ( "supports partial hydration w/patchRoutesOnMiss (leaf fallback)" , async ( ) => {
35
+ let parentDfd = createDeferred ( ) ;
36
+ let childDfd = createDeferred ( ) ;
37
+ let router = createMemoryRouter (
38
+ [
39
+ {
40
+ path : "/" ,
41
+ Component ( ) {
42
+ return (
43
+ < >
44
+ < h1 > Root</ h1 >
45
+ < Outlet />
46
+ </ >
47
+ ) ;
48
+ } ,
49
+ children : [
50
+ {
51
+ id : "parent" ,
52
+ path : "parent" ,
53
+ HydrateFallback : ( ) => < p > Parent Loading...</ p > ,
54
+ loader : ( ) => parentDfd . promise ,
55
+ Component ( ) {
56
+ let data = useLoaderData ( ) as string ;
57
+ return (
58
+ < >
59
+ < h2 > { `Parent - ${ data } ` } </ h2 >
60
+ < Outlet />
61
+ </ >
62
+ ) ;
63
+ } ,
64
+ } ,
65
+ ] ,
66
+ } ,
67
+ ] ,
68
+ {
69
+ future : {
70
+ v7_partialHydration : true ,
71
+ } ,
72
+ unstable_patchRoutesOnMiss ( { path, patch } ) {
73
+ if ( path === "/parent/child" ) {
74
+ patch ( "parent" , [
75
+ {
76
+ path : "child" ,
77
+ loader : ( ) => childDfd . promise ,
78
+ Component ( ) {
79
+ let data = useLoaderData ( ) as string ;
80
+ return < h3 > { `Child - ${ data } ` } </ h3 > ;
81
+ } ,
82
+ } ,
83
+ ] ) ;
84
+ }
85
+ } ,
86
+ initialEntries : [ "/parent/child" ] ,
87
+ }
88
+ ) ;
89
+ let { container } = render (
90
+ < ReactRouter_RouterProvider router = { router } />
91
+ ) ;
92
+
93
+ parentDfd . resolve ( "PARENT DATA" ) ;
94
+ expect ( getHtml ( container ) ) . toMatchInlineSnapshot ( `
95
+ "<div>
96
+ <h1>
97
+ Root
98
+ </h1>
99
+ <p>
100
+ Parent Loading...
101
+ </p>
102
+ </div>"
103
+ ` ) ;
104
+
105
+ childDfd . resolve ( "CHILD DATA" ) ;
106
+ await waitFor ( ( ) => screen . getByText ( / C H I L D D A T A / ) ) ;
107
+ expect ( getHtml ( container ) ) . toMatchInlineSnapshot ( `
108
+ "<div>
109
+ <h1>
110
+ Root
111
+ </h1>
112
+ <h2>
113
+ Parent - PARENT DATA
114
+ </h2>
115
+ <h3>
116
+ Child - CHILD DATA
117
+ </h3>
118
+ </div>"
119
+ ` ) ;
120
+ } ) ;
121
+
122
+ it ( "supports partial hydration w/patchRoutesOnMiss (root fallback)" , async ( ) => {
123
+ let parentDfd = createDeferred ( ) ;
124
+ let childDfd = createDeferred ( ) ;
125
+ let router = createMemoryRouter (
126
+ [
127
+ {
128
+ path : "/" ,
129
+ HydrateFallback : ( ) => < p > Root Loading...</ p > ,
130
+ Component ( ) {
131
+ return (
132
+ < >
133
+ < h1 > Root</ h1 >
134
+ < Outlet />
135
+ </ >
136
+ ) ;
137
+ } ,
138
+ children : [
139
+ {
140
+ id : "parent" ,
141
+ path : "parent" ,
142
+ loader : ( ) => parentDfd . promise ,
143
+ Component ( ) {
144
+ let data = useLoaderData ( ) as string ;
145
+ return (
146
+ < >
147
+ < h2 > { `Parent - ${ data } ` } </ h2 >
148
+ < Outlet />
149
+ </ >
150
+ ) ;
151
+ } ,
152
+ } ,
153
+ ] ,
154
+ } ,
155
+ ] ,
156
+ {
157
+ future : {
158
+ v7_partialHydration : true ,
159
+ } ,
160
+ unstable_patchRoutesOnMiss ( { path, patch } ) {
161
+ if ( path === "/parent/child" ) {
162
+ patch ( "parent" , [
163
+ {
164
+ path : "child" ,
165
+ loader : ( ) => childDfd . promise ,
166
+ Component ( ) {
167
+ let data = useLoaderData ( ) as string ;
168
+ return < h3 > { `Child - ${ data } ` } </ h3 > ;
169
+ } ,
170
+ } ,
171
+ ] ) ;
172
+ }
173
+ } ,
174
+ initialEntries : [ "/parent/child" ] ,
175
+ }
176
+ ) ;
177
+ let { container } = render (
178
+ < ReactRouter_RouterProvider router = { router } />
179
+ ) ;
180
+
181
+ parentDfd . resolve ( "PARENT DATA" ) ;
182
+ expect ( getHtml ( container ) ) . toMatchInlineSnapshot ( `
183
+ "<div>
184
+ <p>
185
+ Root Loading...
186
+ </p>
187
+ </div>"
188
+ ` ) ;
189
+
190
+ childDfd . resolve ( "CHILD DATA" ) ;
191
+ await waitFor ( ( ) => screen . getByText ( / C H I L D D A T A / ) ) ;
192
+ expect ( getHtml ( container ) ) . toMatchInlineSnapshot ( `
193
+ "<div>
194
+ <h1>
195
+ Root
196
+ </h1>
197
+ <h2>
198
+ Parent - PARENT DATA
199
+ </h2>
200
+ <h3>
201
+ Child - CHILD DATA
202
+ </h3>
203
+ </div>"
204
+ ` ) ;
205
+ } ) ;
32
206
} ) ;
33
207
} ) ;
34
208
@@ -39,7 +213,7 @@ function testPartialHydration(
39
213
| typeof createMemoryRouter ,
40
214
RouterProvider :
41
215
| typeof ReactRouterDom_RouterProvider
42
- | typeof ReactRouter_RouterPRovider
216
+ | typeof ReactRouter_RouterProvider
43
217
) {
44
218
let consoleWarn : jest . SpyInstance ;
45
219
0 commit comments