@bleedingdev/modern-js-plugin-tanstack 3.2.0-ultramodern.74 → 3.2.0-ultramodern.76
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/cli/tanstackTypes.js +81 -45
- package/dist/cjs/runtime/routeTree.js +2 -2
- package/dist/esm/cli/tanstackTypes.mjs +81 -45
- package/dist/esm/runtime/routeTree.mjs +2 -2
- package/dist/esm-node/cli/tanstackTypes.mjs +81 -45
- package/dist/esm-node/runtime/routeTree.mjs +2 -2
- package/package.json +9 -9
- package/src/cli/tanstackTypes.ts +81 -45
- package/src/runtime/routeTree.ts +8 -6
|
@@ -256,7 +256,7 @@ function isRedirectResponse(res: Response) {
|
|
|
256
256
|
}
|
|
257
257
|
|
|
258
258
|
function throwTanstackRedirect(location: string) {
|
|
259
|
-
const target = location
|
|
259
|
+
const target = location.length > 0 ? location : '/';
|
|
260
260
|
try {
|
|
261
261
|
void new URL(target);
|
|
262
262
|
throw redirect({ href: target });
|
|
@@ -288,78 +288,114 @@ function createRouteStaticData(opts: {
|
|
|
288
288
|
modernRouteLoader?: unknown;
|
|
289
289
|
} = {};
|
|
290
290
|
|
|
291
|
-
if (opts.modernRouteId) {
|
|
291
|
+
if (typeof opts.modernRouteId === 'string' && opts.modernRouteId.length > 0) {
|
|
292
292
|
staticData.modernRouteId = opts.modernRouteId;
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
-
if (opts.modernRouteLoader) {
|
|
295
|
+
if (typeof opts.modernRouteLoader !== 'undefined') {
|
|
296
296
|
staticData.modernRouteLoader = opts.modernRouteLoader;
|
|
297
297
|
}
|
|
298
298
|
|
|
299
|
-
if (opts.modernRouteAction) {
|
|
299
|
+
if (typeof opts.modernRouteAction !== 'undefined') {
|
|
300
300
|
staticData.modernRouteAction = opts.modernRouteAction;
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
return staticData;
|
|
304
304
|
}
|
|
305
305
|
|
|
306
|
+
function getLoaderSignal(ctx: any): AbortSignal {
|
|
307
|
+
const abortSignal = ctx?.abortController?.signal;
|
|
308
|
+
if (abortSignal instanceof AbortSignal) {
|
|
309
|
+
return abortSignal;
|
|
310
|
+
}
|
|
311
|
+
if (ctx?.signal instanceof AbortSignal) {
|
|
312
|
+
return ctx.signal;
|
|
313
|
+
}
|
|
314
|
+
return new AbortController().signal;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function getLoaderHref(ctx: any): string {
|
|
318
|
+
if (typeof ctx?.location === 'string') {
|
|
319
|
+
return ctx.location;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const publicHref = ctx?.location?.publicHref;
|
|
323
|
+
if (typeof publicHref === 'string') {
|
|
324
|
+
return publicHref;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const href = ctx?.location?.href;
|
|
328
|
+
if (typeof href === 'string') {
|
|
329
|
+
return href;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const urlHref = ctx?.location?.url?.href;
|
|
333
|
+
return typeof urlHref === 'string' ? urlHref : '';
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function getLoaderParams(ctx: any): Record<string, string> {
|
|
337
|
+
return typeof ctx?.params === 'object' && ctx.params !== null ? ctx.params : {};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function handleModernLoaderResult<LoaderResult>(result: LoaderResult): LoaderResult {
|
|
341
|
+
if (isResponse(result)) {
|
|
342
|
+
if (isRedirectResponse(result)) {
|
|
343
|
+
const location = result.headers.get('Location') ?? '/';
|
|
344
|
+
throwTanstackRedirect(location);
|
|
345
|
+
}
|
|
346
|
+
if (result.status === 404) {
|
|
347
|
+
throw notFound();
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
return result;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function handleModernLoaderError(err: unknown): never {
|
|
355
|
+
if (isResponse(err)) {
|
|
356
|
+
if (isRedirectResponse(err)) {
|
|
357
|
+
const location = err.headers.get('Location') ?? '/';
|
|
358
|
+
throwTanstackRedirect(location);
|
|
359
|
+
}
|
|
360
|
+
if (err.status === 404) {
|
|
361
|
+
throw notFound();
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
throw err;
|
|
366
|
+
}
|
|
367
|
+
|
|
306
368
|
function modernLoaderToTanstack<TLoader extends (args: any) => any>(
|
|
307
369
|
opts: { hasSplat: boolean },
|
|
308
370
|
modernLoader: TLoader,
|
|
309
371
|
) {
|
|
310
372
|
type LoaderResult = Awaited<ReturnType<TLoader>>;
|
|
311
373
|
|
|
312
|
-
return
|
|
374
|
+
return (ctx: any): Promise<LoaderResult> => {
|
|
313
375
|
try {
|
|
314
|
-
const signal
|
|
315
|
-
ctx?.abortController?.signal ||
|
|
316
|
-
ctx?.signal ||
|
|
317
|
-
new AbortController().signal;
|
|
376
|
+
const signal = getLoaderSignal(ctx);
|
|
318
377
|
const baseRequest: Request | undefined =
|
|
319
378
|
ctx?.context?.request instanceof Request ? ctx.context.request : undefined;
|
|
320
379
|
|
|
321
|
-
const href =
|
|
322
|
-
typeof ctx?.location === 'string'
|
|
323
|
-
? ctx.location
|
|
324
|
-
: ctx?.location?.publicHref ||
|
|
325
|
-
ctx?.location?.href ||
|
|
326
|
-
ctx?.location?.url?.href ||
|
|
327
|
-
'';
|
|
380
|
+
const href = getLoaderHref(ctx);
|
|
328
381
|
|
|
329
|
-
const request = baseRequest
|
|
382
|
+
const request = baseRequest !== undefined
|
|
330
383
|
? new Request(baseRequest, { signal })
|
|
331
384
|
: new Request(href, { signal });
|
|
332
385
|
|
|
333
|
-
const params = mapParamsForModernLoader(ctx
|
|
334
|
-
|
|
335
|
-
const result = await (modernLoader as any)({
|
|
336
|
-
request,
|
|
337
|
-
params,
|
|
338
|
-
context: ctx?.context?.requestContext,
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
if (isResponse(result)) {
|
|
342
|
-
if (isRedirectResponse(result)) {
|
|
343
|
-
const location = result.headers.get('Location') || '/';
|
|
344
|
-
throwTanstackRedirect(location);
|
|
345
|
-
}
|
|
346
|
-
if (result.status === 404) {
|
|
347
|
-
throw notFound();
|
|
348
|
-
}
|
|
349
|
-
}
|
|
386
|
+
const params = mapParamsForModernLoader(getLoaderParams(ctx), opts.hasSplat);
|
|
350
387
|
|
|
351
|
-
return
|
|
388
|
+
return Promise.resolve(
|
|
389
|
+
(modernLoader as any)({
|
|
390
|
+
request,
|
|
391
|
+
params,
|
|
392
|
+
context: ctx?.context?.requestContext,
|
|
393
|
+
}),
|
|
394
|
+
)
|
|
395
|
+
.then((result: LoaderResult) => handleModernLoaderResult(result))
|
|
396
|
+
.catch(handleModernLoaderError);
|
|
352
397
|
} catch (err) {
|
|
353
|
-
|
|
354
|
-
if (isRedirectResponse(err)) {
|
|
355
|
-
const location = err.headers.get('Location') || '/';
|
|
356
|
-
throwTanstackRedirect(location);
|
|
357
|
-
}
|
|
358
|
-
if (err.status === 404) {
|
|
359
|
-
throw notFound();
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
throw err;
|
|
398
|
+
handleModernLoaderError(err);
|
|
363
399
|
}
|
|
364
400
|
};
|
|
365
401
|
}
|
|
@@ -184,7 +184,7 @@ function wrapModernLoader(modernRoute, modernLoader, revalidationState, options
|
|
|
184
184
|
const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
|
|
185
185
|
const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
|
|
186
186
|
const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
|
|
187
|
-
const request = baseRequest ? new Request(baseRequest, {
|
|
187
|
+
const request = void 0 !== baseRequest ? new Request(baseRequest, {
|
|
188
188
|
signal
|
|
189
189
|
}) : createModernRequest(href, signal);
|
|
190
190
|
const params = mapParamsForModernLoader({
|
|
@@ -249,7 +249,7 @@ function wrapRouteObjectLoader(route, revalidationState, options = {}) {
|
|
|
249
249
|
const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
|
|
250
250
|
const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
|
|
251
251
|
const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
|
|
252
|
-
const request = baseRequest ? new Request(baseRequest, {
|
|
252
|
+
const request = void 0 !== baseRequest ? new Request(baseRequest, {
|
|
253
253
|
signal
|
|
254
254
|
}) : createModernRequest(href, signal);
|
|
255
255
|
const params = mapParamsForRouteObjectLoader({
|
|
@@ -217,7 +217,7 @@ function isRedirectResponse(res: Response) {
|
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
function throwTanstackRedirect(location: string) {
|
|
220
|
-
const target = location
|
|
220
|
+
const target = location.length > 0 ? location : '/';
|
|
221
221
|
try {
|
|
222
222
|
void new URL(target);
|
|
223
223
|
throw redirect({ href: target });
|
|
@@ -249,78 +249,114 @@ function createRouteStaticData(opts: {
|
|
|
249
249
|
modernRouteLoader?: unknown;
|
|
250
250
|
} = {};
|
|
251
251
|
|
|
252
|
-
if (opts.modernRouteId) {
|
|
252
|
+
if (typeof opts.modernRouteId === 'string' && opts.modernRouteId.length > 0) {
|
|
253
253
|
staticData.modernRouteId = opts.modernRouteId;
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
-
if (opts.modernRouteLoader) {
|
|
256
|
+
if (typeof opts.modernRouteLoader !== 'undefined') {
|
|
257
257
|
staticData.modernRouteLoader = opts.modernRouteLoader;
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
-
if (opts.modernRouteAction) {
|
|
260
|
+
if (typeof opts.modernRouteAction !== 'undefined') {
|
|
261
261
|
staticData.modernRouteAction = opts.modernRouteAction;
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
return staticData;
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
+
function getLoaderSignal(ctx: any): AbortSignal {
|
|
268
|
+
const abortSignal = ctx?.abortController?.signal;
|
|
269
|
+
if (abortSignal instanceof AbortSignal) {
|
|
270
|
+
return abortSignal;
|
|
271
|
+
}
|
|
272
|
+
if (ctx?.signal instanceof AbortSignal) {
|
|
273
|
+
return ctx.signal;
|
|
274
|
+
}
|
|
275
|
+
return new AbortController().signal;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function getLoaderHref(ctx: any): string {
|
|
279
|
+
if (typeof ctx?.location === 'string') {
|
|
280
|
+
return ctx.location;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const publicHref = ctx?.location?.publicHref;
|
|
284
|
+
if (typeof publicHref === 'string') {
|
|
285
|
+
return publicHref;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const href = ctx?.location?.href;
|
|
289
|
+
if (typeof href === 'string') {
|
|
290
|
+
return href;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const urlHref = ctx?.location?.url?.href;
|
|
294
|
+
return typeof urlHref === 'string' ? urlHref : '';
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function getLoaderParams(ctx: any): Record<string, string> {
|
|
298
|
+
return typeof ctx?.params === 'object' && ctx.params !== null ? ctx.params : {};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function handleModernLoaderResult<LoaderResult>(result: LoaderResult): LoaderResult {
|
|
302
|
+
if (isResponse(result)) {
|
|
303
|
+
if (isRedirectResponse(result)) {
|
|
304
|
+
const location = result.headers.get('Location') ?? '/';
|
|
305
|
+
throwTanstackRedirect(location);
|
|
306
|
+
}
|
|
307
|
+
if (result.status === 404) {
|
|
308
|
+
throw notFound();
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return result;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function handleModernLoaderError(err: unknown): never {
|
|
316
|
+
if (isResponse(err)) {
|
|
317
|
+
if (isRedirectResponse(err)) {
|
|
318
|
+
const location = err.headers.get('Location') ?? '/';
|
|
319
|
+
throwTanstackRedirect(location);
|
|
320
|
+
}
|
|
321
|
+
if (err.status === 404) {
|
|
322
|
+
throw notFound();
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
throw err;
|
|
327
|
+
}
|
|
328
|
+
|
|
267
329
|
function modernLoaderToTanstack<TLoader extends (args: any) => any>(
|
|
268
330
|
opts: { hasSplat: boolean },
|
|
269
331
|
modernLoader: TLoader,
|
|
270
332
|
) {
|
|
271
333
|
type LoaderResult = Awaited<ReturnType<TLoader>>;
|
|
272
334
|
|
|
273
|
-
return
|
|
335
|
+
return (ctx: any): Promise<LoaderResult> => {
|
|
274
336
|
try {
|
|
275
|
-
const signal
|
|
276
|
-
ctx?.abortController?.signal ||
|
|
277
|
-
ctx?.signal ||
|
|
278
|
-
new AbortController().signal;
|
|
337
|
+
const signal = getLoaderSignal(ctx);
|
|
279
338
|
const baseRequest: Request | undefined =
|
|
280
339
|
ctx?.context?.request instanceof Request ? ctx.context.request : undefined;
|
|
281
340
|
|
|
282
|
-
const href =
|
|
283
|
-
typeof ctx?.location === 'string'
|
|
284
|
-
? ctx.location
|
|
285
|
-
: ctx?.location?.publicHref ||
|
|
286
|
-
ctx?.location?.href ||
|
|
287
|
-
ctx?.location?.url?.href ||
|
|
288
|
-
'';
|
|
341
|
+
const href = getLoaderHref(ctx);
|
|
289
342
|
|
|
290
|
-
const request = baseRequest
|
|
343
|
+
const request = baseRequest !== undefined
|
|
291
344
|
? new Request(baseRequest, { signal })
|
|
292
345
|
: new Request(href, { signal });
|
|
293
346
|
|
|
294
|
-
const params = mapParamsForModernLoader(ctx
|
|
295
|
-
|
|
296
|
-
const result = await (modernLoader as any)({
|
|
297
|
-
request,
|
|
298
|
-
params,
|
|
299
|
-
context: ctx?.context?.requestContext,
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
if (isResponse(result)) {
|
|
303
|
-
if (isRedirectResponse(result)) {
|
|
304
|
-
const location = result.headers.get('Location') || '/';
|
|
305
|
-
throwTanstackRedirect(location);
|
|
306
|
-
}
|
|
307
|
-
if (result.status === 404) {
|
|
308
|
-
throw notFound();
|
|
309
|
-
}
|
|
310
|
-
}
|
|
347
|
+
const params = mapParamsForModernLoader(getLoaderParams(ctx), opts.hasSplat);
|
|
311
348
|
|
|
312
|
-
return
|
|
349
|
+
return Promise.resolve(
|
|
350
|
+
(modernLoader as any)({
|
|
351
|
+
request,
|
|
352
|
+
params,
|
|
353
|
+
context: ctx?.context?.requestContext,
|
|
354
|
+
}),
|
|
355
|
+
)
|
|
356
|
+
.then((result: LoaderResult) => handleModernLoaderResult(result))
|
|
357
|
+
.catch(handleModernLoaderError);
|
|
313
358
|
} catch (err) {
|
|
314
|
-
|
|
315
|
-
if (isRedirectResponse(err)) {
|
|
316
|
-
const location = err.headers.get('Location') || '/';
|
|
317
|
-
throwTanstackRedirect(location);
|
|
318
|
-
}
|
|
319
|
-
if (err.status === 404) {
|
|
320
|
-
throw notFound();
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
throw err;
|
|
359
|
+
handleModernLoaderError(err);
|
|
324
360
|
}
|
|
325
361
|
};
|
|
326
362
|
}
|
|
@@ -154,7 +154,7 @@ function wrapModernLoader(modernRoute, modernLoader, revalidationState, options
|
|
|
154
154
|
const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
|
|
155
155
|
const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
|
|
156
156
|
const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
|
|
157
|
-
const request = baseRequest ? new Request(baseRequest, {
|
|
157
|
+
const request = void 0 !== baseRequest ? new Request(baseRequest, {
|
|
158
158
|
signal
|
|
159
159
|
}) : createModernRequest(href, signal);
|
|
160
160
|
const params = mapParamsForModernLoader({
|
|
@@ -219,7 +219,7 @@ function wrapRouteObjectLoader(route, revalidationState, options = {}) {
|
|
|
219
219
|
const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
|
|
220
220
|
const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
|
|
221
221
|
const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
|
|
222
|
-
const request = baseRequest ? new Request(baseRequest, {
|
|
222
|
+
const request = void 0 !== baseRequest ? new Request(baseRequest, {
|
|
223
223
|
signal
|
|
224
224
|
}) : createModernRequest(href, signal);
|
|
225
225
|
const params = mapParamsForRouteObjectLoader({
|
|
@@ -218,7 +218,7 @@ function isRedirectResponse(res: Response) {
|
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
function throwTanstackRedirect(location: string) {
|
|
221
|
-
const target = location
|
|
221
|
+
const target = location.length > 0 ? location : '/';
|
|
222
222
|
try {
|
|
223
223
|
void new URL(target);
|
|
224
224
|
throw redirect({ href: target });
|
|
@@ -250,78 +250,114 @@ function createRouteStaticData(opts: {
|
|
|
250
250
|
modernRouteLoader?: unknown;
|
|
251
251
|
} = {};
|
|
252
252
|
|
|
253
|
-
if (opts.modernRouteId) {
|
|
253
|
+
if (typeof opts.modernRouteId === 'string' && opts.modernRouteId.length > 0) {
|
|
254
254
|
staticData.modernRouteId = opts.modernRouteId;
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
-
if (opts.modernRouteLoader) {
|
|
257
|
+
if (typeof opts.modernRouteLoader !== 'undefined') {
|
|
258
258
|
staticData.modernRouteLoader = opts.modernRouteLoader;
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
-
if (opts.modernRouteAction) {
|
|
261
|
+
if (typeof opts.modernRouteAction !== 'undefined') {
|
|
262
262
|
staticData.modernRouteAction = opts.modernRouteAction;
|
|
263
263
|
}
|
|
264
264
|
|
|
265
265
|
return staticData;
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
function getLoaderSignal(ctx: any): AbortSignal {
|
|
269
|
+
const abortSignal = ctx?.abortController?.signal;
|
|
270
|
+
if (abortSignal instanceof AbortSignal) {
|
|
271
|
+
return abortSignal;
|
|
272
|
+
}
|
|
273
|
+
if (ctx?.signal instanceof AbortSignal) {
|
|
274
|
+
return ctx.signal;
|
|
275
|
+
}
|
|
276
|
+
return new AbortController().signal;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function getLoaderHref(ctx: any): string {
|
|
280
|
+
if (typeof ctx?.location === 'string') {
|
|
281
|
+
return ctx.location;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const publicHref = ctx?.location?.publicHref;
|
|
285
|
+
if (typeof publicHref === 'string') {
|
|
286
|
+
return publicHref;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const href = ctx?.location?.href;
|
|
290
|
+
if (typeof href === 'string') {
|
|
291
|
+
return href;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const urlHref = ctx?.location?.url?.href;
|
|
295
|
+
return typeof urlHref === 'string' ? urlHref : '';
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function getLoaderParams(ctx: any): Record<string, string> {
|
|
299
|
+
return typeof ctx?.params === 'object' && ctx.params !== null ? ctx.params : {};
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function handleModernLoaderResult<LoaderResult>(result: LoaderResult): LoaderResult {
|
|
303
|
+
if (isResponse(result)) {
|
|
304
|
+
if (isRedirectResponse(result)) {
|
|
305
|
+
const location = result.headers.get('Location') ?? '/';
|
|
306
|
+
throwTanstackRedirect(location);
|
|
307
|
+
}
|
|
308
|
+
if (result.status === 404) {
|
|
309
|
+
throw notFound();
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
return result;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function handleModernLoaderError(err: unknown): never {
|
|
317
|
+
if (isResponse(err)) {
|
|
318
|
+
if (isRedirectResponse(err)) {
|
|
319
|
+
const location = err.headers.get('Location') ?? '/';
|
|
320
|
+
throwTanstackRedirect(location);
|
|
321
|
+
}
|
|
322
|
+
if (err.status === 404) {
|
|
323
|
+
throw notFound();
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
throw err;
|
|
328
|
+
}
|
|
329
|
+
|
|
268
330
|
function modernLoaderToTanstack<TLoader extends (args: any) => any>(
|
|
269
331
|
opts: { hasSplat: boolean },
|
|
270
332
|
modernLoader: TLoader,
|
|
271
333
|
) {
|
|
272
334
|
type LoaderResult = Awaited<ReturnType<TLoader>>;
|
|
273
335
|
|
|
274
|
-
return
|
|
336
|
+
return (ctx: any): Promise<LoaderResult> => {
|
|
275
337
|
try {
|
|
276
|
-
const signal
|
|
277
|
-
ctx?.abortController?.signal ||
|
|
278
|
-
ctx?.signal ||
|
|
279
|
-
new AbortController().signal;
|
|
338
|
+
const signal = getLoaderSignal(ctx);
|
|
280
339
|
const baseRequest: Request | undefined =
|
|
281
340
|
ctx?.context?.request instanceof Request ? ctx.context.request : undefined;
|
|
282
341
|
|
|
283
|
-
const href =
|
|
284
|
-
typeof ctx?.location === 'string'
|
|
285
|
-
? ctx.location
|
|
286
|
-
: ctx?.location?.publicHref ||
|
|
287
|
-
ctx?.location?.href ||
|
|
288
|
-
ctx?.location?.url?.href ||
|
|
289
|
-
'';
|
|
342
|
+
const href = getLoaderHref(ctx);
|
|
290
343
|
|
|
291
|
-
const request = baseRequest
|
|
344
|
+
const request = baseRequest !== undefined
|
|
292
345
|
? new Request(baseRequest, { signal })
|
|
293
346
|
: new Request(href, { signal });
|
|
294
347
|
|
|
295
|
-
const params = mapParamsForModernLoader(ctx
|
|
296
|
-
|
|
297
|
-
const result = await (modernLoader as any)({
|
|
298
|
-
request,
|
|
299
|
-
params,
|
|
300
|
-
context: ctx?.context?.requestContext,
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
if (isResponse(result)) {
|
|
304
|
-
if (isRedirectResponse(result)) {
|
|
305
|
-
const location = result.headers.get('Location') || '/';
|
|
306
|
-
throwTanstackRedirect(location);
|
|
307
|
-
}
|
|
308
|
-
if (result.status === 404) {
|
|
309
|
-
throw notFound();
|
|
310
|
-
}
|
|
311
|
-
}
|
|
348
|
+
const params = mapParamsForModernLoader(getLoaderParams(ctx), opts.hasSplat);
|
|
312
349
|
|
|
313
|
-
return
|
|
350
|
+
return Promise.resolve(
|
|
351
|
+
(modernLoader as any)({
|
|
352
|
+
request,
|
|
353
|
+
params,
|
|
354
|
+
context: ctx?.context?.requestContext,
|
|
355
|
+
}),
|
|
356
|
+
)
|
|
357
|
+
.then((result: LoaderResult) => handleModernLoaderResult(result))
|
|
358
|
+
.catch(handleModernLoaderError);
|
|
314
359
|
} catch (err) {
|
|
315
|
-
|
|
316
|
-
if (isRedirectResponse(err)) {
|
|
317
|
-
const location = err.headers.get('Location') || '/';
|
|
318
|
-
throwTanstackRedirect(location);
|
|
319
|
-
}
|
|
320
|
-
if (err.status === 404) {
|
|
321
|
-
throw notFound();
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
throw err;
|
|
360
|
+
handleModernLoaderError(err);
|
|
325
361
|
}
|
|
326
362
|
};
|
|
327
363
|
}
|
|
@@ -155,7 +155,7 @@ function wrapModernLoader(modernRoute, modernLoader, revalidationState, options
|
|
|
155
155
|
const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
|
|
156
156
|
const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
|
|
157
157
|
const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
|
|
158
|
-
const request = baseRequest ? new Request(baseRequest, {
|
|
158
|
+
const request = void 0 !== baseRequest ? new Request(baseRequest, {
|
|
159
159
|
signal
|
|
160
160
|
}) : createModernRequest(href, signal);
|
|
161
161
|
const params = mapParamsForModernLoader({
|
|
@@ -220,7 +220,7 @@ function wrapRouteObjectLoader(route, revalidationState, options = {}) {
|
|
|
220
220
|
const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
|
|
221
221
|
const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
|
|
222
222
|
const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
|
|
223
|
-
const request = baseRequest ? new Request(baseRequest, {
|
|
223
|
+
const request = void 0 !== baseRequest ? new Request(baseRequest, {
|
|
224
224
|
signal
|
|
225
225
|
}) : createModernRequest(href, signal);
|
|
226
226
|
const params = mapParamsForRouteObjectLoader({
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"modern.js",
|
|
19
19
|
"tanstack-router"
|
|
20
20
|
],
|
|
21
|
-
"version": "3.2.0-ultramodern.
|
|
21
|
+
"version": "3.2.0-ultramodern.76",
|
|
22
22
|
"engines": {
|
|
23
23
|
"node": ">=20"
|
|
24
24
|
},
|
|
@@ -88,13 +88,13 @@
|
|
|
88
88
|
"@swc/helpers": "^0.5.21",
|
|
89
89
|
"@tanstack/react-router": "1.170.8",
|
|
90
90
|
"@tanstack/router-core": "1.171.6",
|
|
91
|
-
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.2.0-ultramodern.
|
|
92
|
-
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.
|
|
93
|
-
"@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.2.0-ultramodern.
|
|
94
|
-
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.
|
|
91
|
+
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.2.0-ultramodern.76",
|
|
92
|
+
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.76",
|
|
93
|
+
"@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.2.0-ultramodern.76",
|
|
94
|
+
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.76"
|
|
95
95
|
},
|
|
96
96
|
"peerDependencies": {
|
|
97
|
-
"@modern-js/runtime": "3.2.0-ultramodern.
|
|
97
|
+
"@modern-js/runtime": "3.2.0-ultramodern.76",
|
|
98
98
|
"react": "^19.2.6",
|
|
99
99
|
"react-dom": "^19.2.6"
|
|
100
100
|
},
|
|
@@ -109,9 +109,9 @@
|
|
|
109
109
|
"@typescript/native-preview": "7.0.0-dev.20260527.2",
|
|
110
110
|
"react": "^19.2.6",
|
|
111
111
|
"react-dom": "^19.2.6",
|
|
112
|
-
"@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.2.0-ultramodern.
|
|
113
|
-
"@
|
|
114
|
-
"@
|
|
112
|
+
"@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.2.0-ultramodern.76",
|
|
113
|
+
"@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.2.0-ultramodern.76",
|
|
114
|
+
"@scripts/rstest-config": "2.66.0"
|
|
115
115
|
},
|
|
116
116
|
"sideEffects": false,
|
|
117
117
|
"publishConfig": {
|
package/src/cli/tanstackTypes.ts
CHANGED
|
@@ -390,7 +390,7 @@ function isRedirectResponse(res: Response) {
|
|
|
390
390
|
}
|
|
391
391
|
|
|
392
392
|
function throwTanstackRedirect(location: string) {
|
|
393
|
-
const target = location
|
|
393
|
+
const target = location.length > 0 ? location : '/';
|
|
394
394
|
try {
|
|
395
395
|
void new URL(target);
|
|
396
396
|
throw redirect({ href: target });
|
|
@@ -422,78 +422,114 @@ function createRouteStaticData(opts: {
|
|
|
422
422
|
modernRouteLoader?: unknown;
|
|
423
423
|
} = {};
|
|
424
424
|
|
|
425
|
-
if (opts.modernRouteId) {
|
|
425
|
+
if (typeof opts.modernRouteId === 'string' && opts.modernRouteId.length > 0) {
|
|
426
426
|
staticData.modernRouteId = opts.modernRouteId;
|
|
427
427
|
}
|
|
428
428
|
|
|
429
|
-
if (opts.modernRouteLoader) {
|
|
429
|
+
if (typeof opts.modernRouteLoader !== 'undefined') {
|
|
430
430
|
staticData.modernRouteLoader = opts.modernRouteLoader;
|
|
431
431
|
}
|
|
432
432
|
|
|
433
|
-
if (opts.modernRouteAction) {
|
|
433
|
+
if (typeof opts.modernRouteAction !== 'undefined') {
|
|
434
434
|
staticData.modernRouteAction = opts.modernRouteAction;
|
|
435
435
|
}
|
|
436
436
|
|
|
437
437
|
return staticData;
|
|
438
438
|
}
|
|
439
439
|
|
|
440
|
+
function getLoaderSignal(ctx: any): AbortSignal {
|
|
441
|
+
const abortSignal = ctx?.abortController?.signal;
|
|
442
|
+
if (abortSignal instanceof AbortSignal) {
|
|
443
|
+
return abortSignal;
|
|
444
|
+
}
|
|
445
|
+
if (ctx?.signal instanceof AbortSignal) {
|
|
446
|
+
return ctx.signal;
|
|
447
|
+
}
|
|
448
|
+
return new AbortController().signal;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function getLoaderHref(ctx: any): string {
|
|
452
|
+
if (typeof ctx?.location === 'string') {
|
|
453
|
+
return ctx.location;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
const publicHref = ctx?.location?.publicHref;
|
|
457
|
+
if (typeof publicHref === 'string') {
|
|
458
|
+
return publicHref;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
const href = ctx?.location?.href;
|
|
462
|
+
if (typeof href === 'string') {
|
|
463
|
+
return href;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
const urlHref = ctx?.location?.url?.href;
|
|
467
|
+
return typeof urlHref === 'string' ? urlHref : '';
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
function getLoaderParams(ctx: any): Record<string, string> {
|
|
471
|
+
return typeof ctx?.params === 'object' && ctx.params !== null ? ctx.params : {};
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
function handleModernLoaderResult<LoaderResult>(result: LoaderResult): LoaderResult {
|
|
475
|
+
if (isResponse(result)) {
|
|
476
|
+
if (isRedirectResponse(result)) {
|
|
477
|
+
const location = result.headers.get('Location') ?? '/';
|
|
478
|
+
throwTanstackRedirect(location);
|
|
479
|
+
}
|
|
480
|
+
if (result.status === 404) {
|
|
481
|
+
throw notFound();
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
return result;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function handleModernLoaderError(err: unknown): never {
|
|
489
|
+
if (isResponse(err)) {
|
|
490
|
+
if (isRedirectResponse(err)) {
|
|
491
|
+
const location = err.headers.get('Location') ?? '/';
|
|
492
|
+
throwTanstackRedirect(location);
|
|
493
|
+
}
|
|
494
|
+
if (err.status === 404) {
|
|
495
|
+
throw notFound();
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
throw err;
|
|
500
|
+
}
|
|
501
|
+
|
|
440
502
|
function modernLoaderToTanstack<TLoader extends (args: any) => any>(
|
|
441
503
|
opts: { hasSplat: boolean },
|
|
442
504
|
modernLoader: TLoader,
|
|
443
505
|
) {
|
|
444
506
|
type LoaderResult = Awaited<ReturnType<TLoader>>;
|
|
445
507
|
|
|
446
|
-
return
|
|
508
|
+
return (ctx: any): Promise<LoaderResult> => {
|
|
447
509
|
try {
|
|
448
|
-
const signal
|
|
449
|
-
ctx?.abortController?.signal ||
|
|
450
|
-
ctx?.signal ||
|
|
451
|
-
new AbortController().signal;
|
|
510
|
+
const signal = getLoaderSignal(ctx);
|
|
452
511
|
const baseRequest: Request | undefined =
|
|
453
512
|
ctx?.context?.request instanceof Request ? ctx.context.request : undefined;
|
|
454
513
|
|
|
455
|
-
const href =
|
|
456
|
-
typeof ctx?.location === 'string'
|
|
457
|
-
? ctx.location
|
|
458
|
-
: ctx?.location?.publicHref ||
|
|
459
|
-
ctx?.location?.href ||
|
|
460
|
-
ctx?.location?.url?.href ||
|
|
461
|
-
'';
|
|
514
|
+
const href = getLoaderHref(ctx);
|
|
462
515
|
|
|
463
|
-
const request = baseRequest
|
|
516
|
+
const request = baseRequest !== undefined
|
|
464
517
|
? new Request(baseRequest, { signal })
|
|
465
518
|
: new Request(href, { signal });
|
|
466
519
|
|
|
467
|
-
const params = mapParamsForModernLoader(ctx
|
|
520
|
+
const params = mapParamsForModernLoader(getLoaderParams(ctx), opts.hasSplat);
|
|
468
521
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
throwTanstackRedirect(location);
|
|
479
|
-
}
|
|
480
|
-
if (result.status === 404) {
|
|
481
|
-
throw notFound();
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
return result as LoaderResult;
|
|
522
|
+
return Promise.resolve(
|
|
523
|
+
(modernLoader as any)({
|
|
524
|
+
request,
|
|
525
|
+
params,
|
|
526
|
+
context: ctx?.context?.requestContext,
|
|
527
|
+
}),
|
|
528
|
+
)
|
|
529
|
+
.then((result: LoaderResult) => handleModernLoaderResult(result))
|
|
530
|
+
.catch(handleModernLoaderError);
|
|
486
531
|
} catch (err) {
|
|
487
|
-
|
|
488
|
-
if (isRedirectResponse(err)) {
|
|
489
|
-
const location = err.headers.get('Location') || '/';
|
|
490
|
-
throwTanstackRedirect(location);
|
|
491
|
-
}
|
|
492
|
-
if (err.status === 404) {
|
|
493
|
-
throw notFound();
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
throw err;
|
|
532
|
+
handleModernLoaderError(err);
|
|
497
533
|
}
|
|
498
534
|
};
|
|
499
535
|
}
|
package/src/runtime/routeTree.ts
CHANGED
|
@@ -428,9 +428,10 @@ function wrapModernLoader(
|
|
|
428
428
|
ctx?.location?.url?.href ||
|
|
429
429
|
'';
|
|
430
430
|
|
|
431
|
-
const request =
|
|
432
|
-
|
|
433
|
-
|
|
431
|
+
const request =
|
|
432
|
+
baseRequest !== undefined
|
|
433
|
+
? new Request(baseRequest, { signal })
|
|
434
|
+
: createModernRequest(href, signal);
|
|
434
435
|
const params = mapParamsForModernLoader({
|
|
435
436
|
modernRoute,
|
|
436
437
|
params: ctx.params || {},
|
|
@@ -544,9 +545,10 @@ function wrapRouteObjectLoader(
|
|
|
544
545
|
ctx?.location?.url?.href ||
|
|
545
546
|
'';
|
|
546
547
|
|
|
547
|
-
const request =
|
|
548
|
-
|
|
549
|
-
|
|
548
|
+
const request =
|
|
549
|
+
baseRequest !== undefined
|
|
550
|
+
? new Request(baseRequest, { signal })
|
|
551
|
+
: createModernRequest(href, signal);
|
|
550
552
|
|
|
551
553
|
const params = mapParamsForRouteObjectLoader({
|
|
552
554
|
route,
|