@bleedingdev/modern-js-runtime 3.2.0-ultramodern.74 → 3.2.0-ultramodern.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/router/cli/code/tanstackTypes.js +81 -45
- package/dist/cjs/router/runtime/tanstack/routeTree.js +2 -2
- package/dist/esm/router/cli/code/tanstackTypes.mjs +81 -45
- package/dist/esm/router/runtime/tanstack/routeTree.mjs +2 -2
- package/dist/esm-node/router/cli/code/tanstackTypes.mjs +81 -45
- package/dist/esm-node/router/runtime/tanstack/routeTree.mjs +2 -2
- package/package.json +8 -8
|
@@ -261,7 +261,7 @@ function isRedirectResponse(res: Response) {
|
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
function throwTanstackRedirect(location: string) {
|
|
264
|
-
const target = location
|
|
264
|
+
const target = location.length > 0 ? location : '/';
|
|
265
265
|
try {
|
|
266
266
|
void new URL(target);
|
|
267
267
|
throw redirect({ href: target });
|
|
@@ -293,78 +293,114 @@ function createRouteStaticData(opts: {
|
|
|
293
293
|
modernRouteLoader?: unknown;
|
|
294
294
|
} = {};
|
|
295
295
|
|
|
296
|
-
if (opts.modernRouteId) {
|
|
296
|
+
if (typeof opts.modernRouteId === 'string' && opts.modernRouteId.length > 0) {
|
|
297
297
|
staticData.modernRouteId = opts.modernRouteId;
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
-
if (opts.modernRouteLoader) {
|
|
300
|
+
if (typeof opts.modernRouteLoader !== 'undefined') {
|
|
301
301
|
staticData.modernRouteLoader = opts.modernRouteLoader;
|
|
302
302
|
}
|
|
303
303
|
|
|
304
|
-
if (opts.modernRouteAction) {
|
|
304
|
+
if (typeof opts.modernRouteAction !== 'undefined') {
|
|
305
305
|
staticData.modernRouteAction = opts.modernRouteAction;
|
|
306
306
|
}
|
|
307
307
|
|
|
308
308
|
return staticData;
|
|
309
309
|
}
|
|
310
310
|
|
|
311
|
+
function getLoaderSignal(ctx: any): AbortSignal {
|
|
312
|
+
const abortSignal = ctx?.abortController?.signal;
|
|
313
|
+
if (abortSignal instanceof AbortSignal) {
|
|
314
|
+
return abortSignal;
|
|
315
|
+
}
|
|
316
|
+
if (ctx?.signal instanceof AbortSignal) {
|
|
317
|
+
return ctx.signal;
|
|
318
|
+
}
|
|
319
|
+
return new AbortController().signal;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function getLoaderHref(ctx: any): string {
|
|
323
|
+
if (typeof ctx?.location === 'string') {
|
|
324
|
+
return ctx.location;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const publicHref = ctx?.location?.publicHref;
|
|
328
|
+
if (typeof publicHref === 'string') {
|
|
329
|
+
return publicHref;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const href = ctx?.location?.href;
|
|
333
|
+
if (typeof href === 'string') {
|
|
334
|
+
return href;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const urlHref = ctx?.location?.url?.href;
|
|
338
|
+
return typeof urlHref === 'string' ? urlHref : '';
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function getLoaderParams(ctx: any): Record<string, string> {
|
|
342
|
+
return typeof ctx?.params === 'object' && ctx.params !== null ? ctx.params : {};
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function handleModernLoaderResult<LoaderResult>(result: LoaderResult): LoaderResult {
|
|
346
|
+
if (isResponse(result)) {
|
|
347
|
+
if (isRedirectResponse(result)) {
|
|
348
|
+
const location = result.headers.get('Location') ?? '/';
|
|
349
|
+
throwTanstackRedirect(location);
|
|
350
|
+
}
|
|
351
|
+
if (result.status === 404) {
|
|
352
|
+
throw notFound();
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return result;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function handleModernLoaderError(err: unknown): never {
|
|
360
|
+
if (isResponse(err)) {
|
|
361
|
+
if (isRedirectResponse(err)) {
|
|
362
|
+
const location = err.headers.get('Location') ?? '/';
|
|
363
|
+
throwTanstackRedirect(location);
|
|
364
|
+
}
|
|
365
|
+
if (err.status === 404) {
|
|
366
|
+
throw notFound();
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
throw err;
|
|
371
|
+
}
|
|
372
|
+
|
|
311
373
|
function modernLoaderToTanstack<TLoader extends (args: any) => any>(
|
|
312
374
|
opts: { hasSplat: boolean },
|
|
313
375
|
modernLoader: TLoader,
|
|
314
376
|
) {
|
|
315
377
|
type LoaderResult = Awaited<ReturnType<TLoader>>;
|
|
316
378
|
|
|
317
|
-
return
|
|
379
|
+
return (ctx: any): Promise<LoaderResult> => {
|
|
318
380
|
try {
|
|
319
|
-
const signal
|
|
320
|
-
ctx?.abortController?.signal ||
|
|
321
|
-
ctx?.signal ||
|
|
322
|
-
new AbortController().signal;
|
|
381
|
+
const signal = getLoaderSignal(ctx);
|
|
323
382
|
const baseRequest: Request | undefined =
|
|
324
383
|
ctx?.context?.request instanceof Request ? ctx.context.request : undefined;
|
|
325
384
|
|
|
326
|
-
const href =
|
|
327
|
-
typeof ctx?.location === 'string'
|
|
328
|
-
? ctx.location
|
|
329
|
-
: ctx?.location?.publicHref ||
|
|
330
|
-
ctx?.location?.href ||
|
|
331
|
-
ctx?.location?.url?.href ||
|
|
332
|
-
'';
|
|
385
|
+
const href = getLoaderHref(ctx);
|
|
333
386
|
|
|
334
|
-
const request = baseRequest
|
|
387
|
+
const request = baseRequest !== undefined
|
|
335
388
|
? new Request(baseRequest, { signal })
|
|
336
389
|
: new Request(href, { signal });
|
|
337
390
|
|
|
338
|
-
const params = mapParamsForModernLoader(ctx
|
|
339
|
-
|
|
340
|
-
const result = await (modernLoader as any)({
|
|
341
|
-
request,
|
|
342
|
-
params,
|
|
343
|
-
context: ctx?.context?.requestContext,
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
if (isResponse(result)) {
|
|
347
|
-
if (isRedirectResponse(result)) {
|
|
348
|
-
const location = result.headers.get('Location') || '/';
|
|
349
|
-
throwTanstackRedirect(location);
|
|
350
|
-
}
|
|
351
|
-
if (result.status === 404) {
|
|
352
|
-
throw notFound();
|
|
353
|
-
}
|
|
354
|
-
}
|
|
391
|
+
const params = mapParamsForModernLoader(getLoaderParams(ctx), opts.hasSplat);
|
|
355
392
|
|
|
356
|
-
return
|
|
393
|
+
return Promise.resolve(
|
|
394
|
+
(modernLoader as any)({
|
|
395
|
+
request,
|
|
396
|
+
params,
|
|
397
|
+
context: ctx?.context?.requestContext,
|
|
398
|
+
}),
|
|
399
|
+
)
|
|
400
|
+
.then((result: LoaderResult) => handleModernLoaderResult(result))
|
|
401
|
+
.catch(handleModernLoaderError);
|
|
357
402
|
} catch (err) {
|
|
358
|
-
|
|
359
|
-
if (isRedirectResponse(err)) {
|
|
360
|
-
const location = err.headers.get('Location') || '/';
|
|
361
|
-
throwTanstackRedirect(location);
|
|
362
|
-
}
|
|
363
|
-
if (err.status === 404) {
|
|
364
|
-
throw notFound();
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
throw err;
|
|
403
|
+
handleModernLoaderError(err);
|
|
368
404
|
}
|
|
369
405
|
};
|
|
370
406
|
}
|
|
@@ -169,7 +169,7 @@ function wrapModernLoader(modernRoute, modernLoader, revalidationState) {
|
|
|
169
169
|
const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
|
|
170
170
|
const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
|
|
171
171
|
const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
|
|
172
|
-
const request = baseRequest ? new Request(baseRequest, {
|
|
172
|
+
const request = void 0 !== baseRequest ? new Request(baseRequest, {
|
|
173
173
|
signal
|
|
174
174
|
}) : createModernRequest(href, signal);
|
|
175
175
|
const params = mapParamsForModernLoader({
|
|
@@ -232,7 +232,7 @@ function wrapRouteObjectLoader(route, revalidationState) {
|
|
|
232
232
|
const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
|
|
233
233
|
const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
|
|
234
234
|
const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
|
|
235
|
-
const request = baseRequest ? new Request(baseRequest, {
|
|
235
|
+
const request = void 0 !== baseRequest ? new Request(baseRequest, {
|
|
236
236
|
signal
|
|
237
237
|
}) : createModernRequest(href, signal);
|
|
238
238
|
const params = mapParamsForRouteObjectLoader({
|
|
@@ -222,7 +222,7 @@ function isRedirectResponse(res: Response) {
|
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
function throwTanstackRedirect(location: string) {
|
|
225
|
-
const target = location
|
|
225
|
+
const target = location.length > 0 ? location : '/';
|
|
226
226
|
try {
|
|
227
227
|
void new URL(target);
|
|
228
228
|
throw redirect({ href: target });
|
|
@@ -254,78 +254,114 @@ function createRouteStaticData(opts: {
|
|
|
254
254
|
modernRouteLoader?: unknown;
|
|
255
255
|
} = {};
|
|
256
256
|
|
|
257
|
-
if (opts.modernRouteId) {
|
|
257
|
+
if (typeof opts.modernRouteId === 'string' && opts.modernRouteId.length > 0) {
|
|
258
258
|
staticData.modernRouteId = opts.modernRouteId;
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
-
if (opts.modernRouteLoader) {
|
|
261
|
+
if (typeof opts.modernRouteLoader !== 'undefined') {
|
|
262
262
|
staticData.modernRouteLoader = opts.modernRouteLoader;
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
-
if (opts.modernRouteAction) {
|
|
265
|
+
if (typeof opts.modernRouteAction !== 'undefined') {
|
|
266
266
|
staticData.modernRouteAction = opts.modernRouteAction;
|
|
267
267
|
}
|
|
268
268
|
|
|
269
269
|
return staticData;
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
+
function getLoaderSignal(ctx: any): AbortSignal {
|
|
273
|
+
const abortSignal = ctx?.abortController?.signal;
|
|
274
|
+
if (abortSignal instanceof AbortSignal) {
|
|
275
|
+
return abortSignal;
|
|
276
|
+
}
|
|
277
|
+
if (ctx?.signal instanceof AbortSignal) {
|
|
278
|
+
return ctx.signal;
|
|
279
|
+
}
|
|
280
|
+
return new AbortController().signal;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function getLoaderHref(ctx: any): string {
|
|
284
|
+
if (typeof ctx?.location === 'string') {
|
|
285
|
+
return ctx.location;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const publicHref = ctx?.location?.publicHref;
|
|
289
|
+
if (typeof publicHref === 'string') {
|
|
290
|
+
return publicHref;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const href = ctx?.location?.href;
|
|
294
|
+
if (typeof href === 'string') {
|
|
295
|
+
return href;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const urlHref = ctx?.location?.url?.href;
|
|
299
|
+
return typeof urlHref === 'string' ? urlHref : '';
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function getLoaderParams(ctx: any): Record<string, string> {
|
|
303
|
+
return typeof ctx?.params === 'object' && ctx.params !== null ? ctx.params : {};
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function handleModernLoaderResult<LoaderResult>(result: LoaderResult): LoaderResult {
|
|
307
|
+
if (isResponse(result)) {
|
|
308
|
+
if (isRedirectResponse(result)) {
|
|
309
|
+
const location = result.headers.get('Location') ?? '/';
|
|
310
|
+
throwTanstackRedirect(location);
|
|
311
|
+
}
|
|
312
|
+
if (result.status === 404) {
|
|
313
|
+
throw notFound();
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
return result;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function handleModernLoaderError(err: unknown): never {
|
|
321
|
+
if (isResponse(err)) {
|
|
322
|
+
if (isRedirectResponse(err)) {
|
|
323
|
+
const location = err.headers.get('Location') ?? '/';
|
|
324
|
+
throwTanstackRedirect(location);
|
|
325
|
+
}
|
|
326
|
+
if (err.status === 404) {
|
|
327
|
+
throw notFound();
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
throw err;
|
|
332
|
+
}
|
|
333
|
+
|
|
272
334
|
function modernLoaderToTanstack<TLoader extends (args: any) => any>(
|
|
273
335
|
opts: { hasSplat: boolean },
|
|
274
336
|
modernLoader: TLoader,
|
|
275
337
|
) {
|
|
276
338
|
type LoaderResult = Awaited<ReturnType<TLoader>>;
|
|
277
339
|
|
|
278
|
-
return
|
|
340
|
+
return (ctx: any): Promise<LoaderResult> => {
|
|
279
341
|
try {
|
|
280
|
-
const signal
|
|
281
|
-
ctx?.abortController?.signal ||
|
|
282
|
-
ctx?.signal ||
|
|
283
|
-
new AbortController().signal;
|
|
342
|
+
const signal = getLoaderSignal(ctx);
|
|
284
343
|
const baseRequest: Request | undefined =
|
|
285
344
|
ctx?.context?.request instanceof Request ? ctx.context.request : undefined;
|
|
286
345
|
|
|
287
|
-
const href =
|
|
288
|
-
typeof ctx?.location === 'string'
|
|
289
|
-
? ctx.location
|
|
290
|
-
: ctx?.location?.publicHref ||
|
|
291
|
-
ctx?.location?.href ||
|
|
292
|
-
ctx?.location?.url?.href ||
|
|
293
|
-
'';
|
|
346
|
+
const href = getLoaderHref(ctx);
|
|
294
347
|
|
|
295
|
-
const request = baseRequest
|
|
348
|
+
const request = baseRequest !== undefined
|
|
296
349
|
? new Request(baseRequest, { signal })
|
|
297
350
|
: new Request(href, { signal });
|
|
298
351
|
|
|
299
|
-
const params = mapParamsForModernLoader(ctx
|
|
300
|
-
|
|
301
|
-
const result = await (modernLoader as any)({
|
|
302
|
-
request,
|
|
303
|
-
params,
|
|
304
|
-
context: ctx?.context?.requestContext,
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
if (isResponse(result)) {
|
|
308
|
-
if (isRedirectResponse(result)) {
|
|
309
|
-
const location = result.headers.get('Location') || '/';
|
|
310
|
-
throwTanstackRedirect(location);
|
|
311
|
-
}
|
|
312
|
-
if (result.status === 404) {
|
|
313
|
-
throw notFound();
|
|
314
|
-
}
|
|
315
|
-
}
|
|
352
|
+
const params = mapParamsForModernLoader(getLoaderParams(ctx), opts.hasSplat);
|
|
316
353
|
|
|
317
|
-
return
|
|
354
|
+
return Promise.resolve(
|
|
355
|
+
(modernLoader as any)({
|
|
356
|
+
request,
|
|
357
|
+
params,
|
|
358
|
+
context: ctx?.context?.requestContext,
|
|
359
|
+
}),
|
|
360
|
+
)
|
|
361
|
+
.then((result: LoaderResult) => handleModernLoaderResult(result))
|
|
362
|
+
.catch(handleModernLoaderError);
|
|
318
363
|
} catch (err) {
|
|
319
|
-
|
|
320
|
-
if (isRedirectResponse(err)) {
|
|
321
|
-
const location = err.headers.get('Location') || '/';
|
|
322
|
-
throwTanstackRedirect(location);
|
|
323
|
-
}
|
|
324
|
-
if (err.status === 404) {
|
|
325
|
-
throw notFound();
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
throw err;
|
|
364
|
+
handleModernLoaderError(err);
|
|
329
365
|
}
|
|
330
366
|
};
|
|
331
367
|
}
|
|
@@ -139,7 +139,7 @@ function wrapModernLoader(modernRoute, modernLoader, revalidationState) {
|
|
|
139
139
|
const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
|
|
140
140
|
const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
|
|
141
141
|
const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
|
|
142
|
-
const request = baseRequest ? new Request(baseRequest, {
|
|
142
|
+
const request = void 0 !== baseRequest ? new Request(baseRequest, {
|
|
143
143
|
signal
|
|
144
144
|
}) : createModernRequest(href, signal);
|
|
145
145
|
const params = mapParamsForModernLoader({
|
|
@@ -202,7 +202,7 @@ function wrapRouteObjectLoader(route, revalidationState) {
|
|
|
202
202
|
const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
|
|
203
203
|
const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
|
|
204
204
|
const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
|
|
205
|
-
const request = baseRequest ? new Request(baseRequest, {
|
|
205
|
+
const request = void 0 !== baseRequest ? new Request(baseRequest, {
|
|
206
206
|
signal
|
|
207
207
|
}) : createModernRequest(href, signal);
|
|
208
208
|
const params = mapParamsForRouteObjectLoader({
|
|
@@ -223,7 +223,7 @@ function isRedirectResponse(res: Response) {
|
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
function throwTanstackRedirect(location: string) {
|
|
226
|
-
const target = location
|
|
226
|
+
const target = location.length > 0 ? location : '/';
|
|
227
227
|
try {
|
|
228
228
|
void new URL(target);
|
|
229
229
|
throw redirect({ href: target });
|
|
@@ -255,78 +255,114 @@ function createRouteStaticData(opts: {
|
|
|
255
255
|
modernRouteLoader?: unknown;
|
|
256
256
|
} = {};
|
|
257
257
|
|
|
258
|
-
if (opts.modernRouteId) {
|
|
258
|
+
if (typeof opts.modernRouteId === 'string' && opts.modernRouteId.length > 0) {
|
|
259
259
|
staticData.modernRouteId = opts.modernRouteId;
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
if (opts.modernRouteLoader) {
|
|
262
|
+
if (typeof opts.modernRouteLoader !== 'undefined') {
|
|
263
263
|
staticData.modernRouteLoader = opts.modernRouteLoader;
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
-
if (opts.modernRouteAction) {
|
|
266
|
+
if (typeof opts.modernRouteAction !== 'undefined') {
|
|
267
267
|
staticData.modernRouteAction = opts.modernRouteAction;
|
|
268
268
|
}
|
|
269
269
|
|
|
270
270
|
return staticData;
|
|
271
271
|
}
|
|
272
272
|
|
|
273
|
+
function getLoaderSignal(ctx: any): AbortSignal {
|
|
274
|
+
const abortSignal = ctx?.abortController?.signal;
|
|
275
|
+
if (abortSignal instanceof AbortSignal) {
|
|
276
|
+
return abortSignal;
|
|
277
|
+
}
|
|
278
|
+
if (ctx?.signal instanceof AbortSignal) {
|
|
279
|
+
return ctx.signal;
|
|
280
|
+
}
|
|
281
|
+
return new AbortController().signal;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function getLoaderHref(ctx: any): string {
|
|
285
|
+
if (typeof ctx?.location === 'string') {
|
|
286
|
+
return ctx.location;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const publicHref = ctx?.location?.publicHref;
|
|
290
|
+
if (typeof publicHref === 'string') {
|
|
291
|
+
return publicHref;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const href = ctx?.location?.href;
|
|
295
|
+
if (typeof href === 'string') {
|
|
296
|
+
return href;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const urlHref = ctx?.location?.url?.href;
|
|
300
|
+
return typeof urlHref === 'string' ? urlHref : '';
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function getLoaderParams(ctx: any): Record<string, string> {
|
|
304
|
+
return typeof ctx?.params === 'object' && ctx.params !== null ? ctx.params : {};
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function handleModernLoaderResult<LoaderResult>(result: LoaderResult): LoaderResult {
|
|
308
|
+
if (isResponse(result)) {
|
|
309
|
+
if (isRedirectResponse(result)) {
|
|
310
|
+
const location = result.headers.get('Location') ?? '/';
|
|
311
|
+
throwTanstackRedirect(location);
|
|
312
|
+
}
|
|
313
|
+
if (result.status === 404) {
|
|
314
|
+
throw notFound();
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return result;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function handleModernLoaderError(err: unknown): never {
|
|
322
|
+
if (isResponse(err)) {
|
|
323
|
+
if (isRedirectResponse(err)) {
|
|
324
|
+
const location = err.headers.get('Location') ?? '/';
|
|
325
|
+
throwTanstackRedirect(location);
|
|
326
|
+
}
|
|
327
|
+
if (err.status === 404) {
|
|
328
|
+
throw notFound();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
throw err;
|
|
333
|
+
}
|
|
334
|
+
|
|
273
335
|
function modernLoaderToTanstack<TLoader extends (args: any) => any>(
|
|
274
336
|
opts: { hasSplat: boolean },
|
|
275
337
|
modernLoader: TLoader,
|
|
276
338
|
) {
|
|
277
339
|
type LoaderResult = Awaited<ReturnType<TLoader>>;
|
|
278
340
|
|
|
279
|
-
return
|
|
341
|
+
return (ctx: any): Promise<LoaderResult> => {
|
|
280
342
|
try {
|
|
281
|
-
const signal
|
|
282
|
-
ctx?.abortController?.signal ||
|
|
283
|
-
ctx?.signal ||
|
|
284
|
-
new AbortController().signal;
|
|
343
|
+
const signal = getLoaderSignal(ctx);
|
|
285
344
|
const baseRequest: Request | undefined =
|
|
286
345
|
ctx?.context?.request instanceof Request ? ctx.context.request : undefined;
|
|
287
346
|
|
|
288
|
-
const href =
|
|
289
|
-
typeof ctx?.location === 'string'
|
|
290
|
-
? ctx.location
|
|
291
|
-
: ctx?.location?.publicHref ||
|
|
292
|
-
ctx?.location?.href ||
|
|
293
|
-
ctx?.location?.url?.href ||
|
|
294
|
-
'';
|
|
347
|
+
const href = getLoaderHref(ctx);
|
|
295
348
|
|
|
296
|
-
const request = baseRequest
|
|
349
|
+
const request = baseRequest !== undefined
|
|
297
350
|
? new Request(baseRequest, { signal })
|
|
298
351
|
: new Request(href, { signal });
|
|
299
352
|
|
|
300
|
-
const params = mapParamsForModernLoader(ctx
|
|
301
|
-
|
|
302
|
-
const result = await (modernLoader as any)({
|
|
303
|
-
request,
|
|
304
|
-
params,
|
|
305
|
-
context: ctx?.context?.requestContext,
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
if (isResponse(result)) {
|
|
309
|
-
if (isRedirectResponse(result)) {
|
|
310
|
-
const location = result.headers.get('Location') || '/';
|
|
311
|
-
throwTanstackRedirect(location);
|
|
312
|
-
}
|
|
313
|
-
if (result.status === 404) {
|
|
314
|
-
throw notFound();
|
|
315
|
-
}
|
|
316
|
-
}
|
|
353
|
+
const params = mapParamsForModernLoader(getLoaderParams(ctx), opts.hasSplat);
|
|
317
354
|
|
|
318
|
-
return
|
|
355
|
+
return Promise.resolve(
|
|
356
|
+
(modernLoader as any)({
|
|
357
|
+
request,
|
|
358
|
+
params,
|
|
359
|
+
context: ctx?.context?.requestContext,
|
|
360
|
+
}),
|
|
361
|
+
)
|
|
362
|
+
.then((result: LoaderResult) => handleModernLoaderResult(result))
|
|
363
|
+
.catch(handleModernLoaderError);
|
|
319
364
|
} catch (err) {
|
|
320
|
-
|
|
321
|
-
if (isRedirectResponse(err)) {
|
|
322
|
-
const location = err.headers.get('Location') || '/';
|
|
323
|
-
throwTanstackRedirect(location);
|
|
324
|
-
}
|
|
325
|
-
if (err.status === 404) {
|
|
326
|
-
throw notFound();
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
throw err;
|
|
365
|
+
handleModernLoaderError(err);
|
|
330
366
|
}
|
|
331
367
|
};
|
|
332
368
|
}
|
|
@@ -140,7 +140,7 @@ function wrapModernLoader(modernRoute, modernLoader, revalidationState) {
|
|
|
140
140
|
const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
|
|
141
141
|
const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
|
|
142
142
|
const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
|
|
143
|
-
const request = baseRequest ? new Request(baseRequest, {
|
|
143
|
+
const request = void 0 !== baseRequest ? new Request(baseRequest, {
|
|
144
144
|
signal
|
|
145
145
|
}) : createModernRequest(href, signal);
|
|
146
146
|
const params = mapParamsForModernLoader({
|
|
@@ -203,7 +203,7 @@ function wrapRouteObjectLoader(route, revalidationState) {
|
|
|
203
203
|
const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
|
|
204
204
|
const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
|
|
205
205
|
const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
|
|
206
|
-
const request = baseRequest ? new Request(baseRequest, {
|
|
206
|
+
const request = void 0 !== baseRequest ? new Request(baseRequest, {
|
|
207
207
|
signal
|
|
208
208
|
}) : createModernRequest(href, signal);
|
|
209
209
|
const params = mapParamsForRouteObjectLoader({
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"modern",
|
|
18
18
|
"modern.js"
|
|
19
19
|
],
|
|
20
|
-
"version": "3.2.0-ultramodern.
|
|
20
|
+
"version": "3.2.0-ultramodern.77",
|
|
21
21
|
"engines": {
|
|
22
22
|
"node": ">=20"
|
|
23
23
|
},
|
|
@@ -234,12 +234,12 @@
|
|
|
234
234
|
"isbot": "5.1.40",
|
|
235
235
|
"react-helmet": "^6.1.0",
|
|
236
236
|
"react-is": "^19.2.6",
|
|
237
|
-
"@modern-js/plugin
|
|
238
|
-
"@modern-js/
|
|
239
|
-
"@modern-js/
|
|
240
|
-
"@modern-js/
|
|
241
|
-
"@modern-js/
|
|
242
|
-
"@modern-js/
|
|
237
|
+
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.2.0-ultramodern.77",
|
|
238
|
+
"@modern-js/plugin-data-loader": "npm:@bleedingdev/modern-js-plugin-data-loader@3.2.0-ultramodern.77",
|
|
239
|
+
"@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.2.0-ultramodern.77",
|
|
240
|
+
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.77",
|
|
241
|
+
"@modern-js/render": "npm:@bleedingdev/modern-js-render@3.2.0-ultramodern.77",
|
|
242
|
+
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.77"
|
|
243
243
|
},
|
|
244
244
|
"peerDependencies": {
|
|
245
245
|
"react": "^19.2.6",
|
|
@@ -258,7 +258,7 @@
|
|
|
258
258
|
"@typescript/native-preview": "7.0.0-dev.20260527.2",
|
|
259
259
|
"react": "^19.2.6",
|
|
260
260
|
"react-dom": "^19.2.6",
|
|
261
|
-
"@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.2.0-ultramodern.
|
|
261
|
+
"@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.2.0-ultramodern.77",
|
|
262
262
|
"@scripts/rstest-config": "2.66.0"
|
|
263
263
|
},
|
|
264
264
|
"sideEffects": false,
|