@@ -162,6 +162,164 @@ describe('assignErrorIfEmpty', () => {
162
162
assignErrorIfEmpty ( prerenderedRoutes , [ ] )
163
163
expect ( prerenderedRoutes ) . toEqual ( [ ] )
164
164
} )
165
+
166
+ it ( 'should handle blog/[slug] not throwing when concrete routes exist (from docs example)' , ( ) => {
167
+ const prerenderedRoutes : PrerenderedRoute [ ] = [
168
+ {
169
+ params : { } ,
170
+ pathname : '/blog/[slug]' ,
171
+ encodedPathname : '/blog/[slug]' ,
172
+ fallbackRouteParams : [ 'slug' ] ,
173
+ fallbackMode : FallbackMode . NOT_FOUND ,
174
+ fallbackRootParams : [ ] ,
175
+ throwOnEmptyStaticShell : true ,
176
+ } ,
177
+ {
178
+ params : { slug : 'first-post' } ,
179
+ pathname : '/blog/first-post' ,
180
+ encodedPathname : '/blog/first-post' ,
181
+ fallbackRouteParams : [ ] ,
182
+ fallbackMode : FallbackMode . NOT_FOUND ,
183
+ fallbackRootParams : [ ] ,
184
+ throwOnEmptyStaticShell : true ,
185
+ } ,
186
+ {
187
+ params : { slug : 'second-post' } ,
188
+ pathname : '/blog/second-post' ,
189
+ encodedPathname : '/blog/second-post' ,
190
+ fallbackRouteParams : [ ] ,
191
+ fallbackMode : FallbackMode . NOT_FOUND ,
192
+ fallbackRootParams : [ ] ,
193
+ throwOnEmptyStaticShell : true ,
194
+ } ,
195
+ ]
196
+
197
+ assignErrorIfEmpty ( prerenderedRoutes , [ 'slug' ] )
198
+
199
+ expect ( prerenderedRoutes [ 0 ] . throwOnEmptyStaticShell ) . toBe ( false ) // Should not throw - has concrete children
200
+ expect ( prerenderedRoutes [ 1 ] . throwOnEmptyStaticShell ) . toBe ( true ) // Should throw - concrete route
201
+ expect ( prerenderedRoutes [ 2 ] . throwOnEmptyStaticShell ) . toBe ( true ) // Should throw - concrete route
202
+ } )
203
+
204
+ it ( 'should handle catch-all routes with different fallback parameter counts (from docs example)' , ( ) => {
205
+ const prerenderedRoutes : PrerenderedRoute [ ] = [
206
+ {
207
+ params : { } ,
208
+ pathname : '/[id]/[...slug]' ,
209
+ encodedPathname : '/[id]/[...slug]' ,
210
+ fallbackRouteParams : [ 'id' , 'slug' ] ,
211
+ fallbackMode : FallbackMode . NOT_FOUND ,
212
+ fallbackRootParams : [ ] ,
213
+ throwOnEmptyStaticShell : true ,
214
+ } ,
215
+ {
216
+ params : { id : '1234' } ,
217
+ pathname : '/1234/[...slug]' ,
218
+ encodedPathname : '/1234/[...slug]' ,
219
+ fallbackRouteParams : [ 'slug' ] ,
220
+ fallbackMode : FallbackMode . NOT_FOUND ,
221
+ fallbackRootParams : [ ] ,
222
+ throwOnEmptyStaticShell : true ,
223
+ } ,
224
+ {
225
+ params : { id : '1234' , slug : [ 'about' , 'us' ] } ,
226
+ pathname : '/1234/about/us' ,
227
+ encodedPathname : '/1234/about/us' ,
228
+ fallbackRouteParams : [ ] ,
229
+ fallbackMode : FallbackMode . NOT_FOUND ,
230
+ fallbackRootParams : [ ] ,
231
+ throwOnEmptyStaticShell : true ,
232
+ } ,
233
+ ]
234
+
235
+ assignErrorIfEmpty ( prerenderedRoutes , [ 'id' , 'slug' ] )
236
+
237
+ expect ( prerenderedRoutes [ 0 ] . throwOnEmptyStaticShell ) . toBe ( false ) // Should not throw - has children
238
+ expect ( prerenderedRoutes [ 1 ] . throwOnEmptyStaticShell ) . toBe ( false ) // Should not throw - has children
239
+ expect ( prerenderedRoutes [ 2 ] . throwOnEmptyStaticShell ) . toBe ( true ) // Should throw - concrete route
240
+ } )
241
+
242
+ it ( 'should handle nested routes with multiple parameter depths' , ( ) => {
243
+ const prerenderedRoutes : PrerenderedRoute [ ] = [
244
+ {
245
+ params : { } ,
246
+ pathname : '/[category]/[subcategory]/[item]' ,
247
+ encodedPathname : '/[category]/[subcategory]/[item]' ,
248
+ fallbackRouteParams : [ 'category' , 'subcategory' , 'item' ] ,
249
+ fallbackMode : FallbackMode . NOT_FOUND ,
250
+ fallbackRootParams : [ ] ,
251
+ throwOnEmptyStaticShell : true ,
252
+ } ,
253
+ {
254
+ params : { category : 'electronics' } ,
255
+ pathname : '/electronics/[subcategory]/[item]' ,
256
+ encodedPathname : '/electronics/[subcategory]/[item]' ,
257
+ fallbackRouteParams : [ 'subcategory' , 'item' ] ,
258
+ fallbackMode : FallbackMode . NOT_FOUND ,
259
+ fallbackRootParams : [ ] ,
260
+ throwOnEmptyStaticShell : true ,
261
+ } ,
262
+ {
263
+ params : { category : 'electronics' , subcategory : 'phones' } ,
264
+ pathname : '/electronics/phones/[item]' ,
265
+ encodedPathname : '/electronics/phones/[item]' ,
266
+ fallbackRouteParams : [ 'item' ] ,
267
+ fallbackMode : FallbackMode . NOT_FOUND ,
268
+ fallbackRootParams : [ ] ,
269
+ throwOnEmptyStaticShell : true ,
270
+ } ,
271
+ {
272
+ params : {
273
+ category : 'electronics' ,
274
+ subcategory : 'phones' ,
275
+ item : 'iphone' ,
276
+ } ,
277
+ pathname : '/electronics/phones/iphone' ,
278
+ encodedPathname : '/electronics/phones/iphone' ,
279
+ fallbackRouteParams : [ ] ,
280
+ fallbackMode : FallbackMode . NOT_FOUND ,
281
+ fallbackRootParams : [ ] ,
282
+ throwOnEmptyStaticShell : true ,
283
+ } ,
284
+ ]
285
+
286
+ assignErrorIfEmpty ( prerenderedRoutes , [ 'category' , 'subcategory' , 'item' ] )
287
+
288
+ // All except the last one should not throw on empty static shell
289
+ expect ( prerenderedRoutes [ 0 ] . throwOnEmptyStaticShell ) . toBe ( false )
290
+ expect ( prerenderedRoutes [ 1 ] . throwOnEmptyStaticShell ) . toBe ( false )
291
+ expect ( prerenderedRoutes [ 2 ] . throwOnEmptyStaticShell ) . toBe ( false )
292
+ expect ( prerenderedRoutes [ 3 ] . throwOnEmptyStaticShell ) . toBe ( true )
293
+ } )
294
+
295
+ it ( 'should handle routes at same trie node with different fallback parameter lengths' , ( ) => {
296
+ const prerenderedRoutes : PrerenderedRoute [ ] = [
297
+ {
298
+ params : { locale : 'en' } ,
299
+ pathname : '/en/[...segments]' ,
300
+ encodedPathname : '/en/[...segments]' ,
301
+ fallbackRouteParams : [ 'segments' ] ,
302
+ fallbackMode : FallbackMode . NOT_FOUND ,
303
+ fallbackRootParams : [ ] ,
304
+ throwOnEmptyStaticShell : true ,
305
+ } ,
306
+ {
307
+ params : { locale : 'en' } ,
308
+ pathname : '/en' ,
309
+ encodedPathname : '/en' ,
310
+ fallbackRouteParams : [ ] ,
311
+ fallbackMode : FallbackMode . NOT_FOUND ,
312
+ fallbackRootParams : [ ] ,
313
+ throwOnEmptyStaticShell : true ,
314
+ } ,
315
+ ]
316
+
317
+ assignErrorIfEmpty ( prerenderedRoutes , [ 'locale' , 'segments' ] )
318
+
319
+ // The route with more fallback params should not throw on empty static shell
320
+ expect ( prerenderedRoutes [ 0 ] . throwOnEmptyStaticShell ) . toBe ( false )
321
+ expect ( prerenderedRoutes [ 1 ] . throwOnEmptyStaticShell ) . toBe ( true )
322
+ } )
165
323
} )
166
324
167
325
describe ( 'filterUniqueParams' , ( ) => {
0 commit comments