react-router 0.0.0-experimental-3278f3ca6 → 0.0.0-experimental-312bddb22

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * React Router v0.0.0-experimental-3278f3ca6
2
+ * React Router v0.0.0-experimental-312bddb22
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
package/dist/index.d.ts CHANGED
@@ -24,20 +24,15 @@ export { ServerRouter } from "./lib/dom/ssr/server";
24
24
  export type { RoutesTestStubProps } from "./lib/dom/ssr/routes-test-stub";
25
25
  export { createRoutesStub } from "./lib/dom/ssr/routes-test-stub";
26
26
  export { createCookie, isCookie } from "./lib/server-runtime/cookies";
27
- export { composeUploadHandlers as unstable_composeUploadHandlers, parseMultipartFormData as unstable_parseMultipartFormData, } from "./lib/server-runtime/formData";
28
27
  export { createRequestHandler } from "./lib/server-runtime/server";
29
28
  export { createSession, createSessionStorage, isSession, } from "./lib/server-runtime/sessions";
30
29
  export { createCookieSessionStorage } from "./lib/server-runtime/sessions/cookieStorage";
31
30
  export { createMemorySessionStorage } from "./lib/server-runtime/sessions/memoryStorage";
32
- export { createMemoryUploadHandler as unstable_createMemoryUploadHandler } from "./lib/server-runtime/upload/memoryUploadHandler";
33
- export { MaxPartSizeExceededError } from "./lib/server-runtime/upload/errors";
34
31
  export { setDevServerHooks as unstable_setDevServerHooks } from "./lib/server-runtime/dev";
35
32
  export type { IsCookieFunction } from "./lib/server-runtime/cookies";
36
33
  export type { CreateRequestHandlerFunction } from "./lib/server-runtime/server";
37
34
  export type { IsSessionFunction } from "./lib/server-runtime/sessions";
38
35
  export type { HandleDataRequestFunction, HandleDocumentRequestFunction, HandleErrorFunction, ServerBuild, ServerEntryModule, } from "./lib/server-runtime/build";
39
- export type { UploadHandlerPart, UploadHandler, } from "./lib/server-runtime/formData";
40
- export type { MemoryUploadHandlerOptions, MemoryUploadHandlerFilterArgs, } from "./lib/server-runtime/upload/memoryUploadHandler";
41
36
  export type { Cookie, CookieOptions, CookieParseOptions, CookieSerializeOptions, CookieSignatureOptions, } from "./lib/server-runtime/cookies";
42
37
  export type { AppLoadContext } from "./lib/server-runtime/data";
43
38
  export type { PageLinkDescriptor, HtmlLinkDescriptor, LinkDescriptor, } from "./lib/router/links";
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * React Router v0.0.0-experimental-3278f3ca6
2
+ * React Router v0.0.0-experimental-312bddb22
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -11,53 +11,8 @@
11
11
  import * as React from 'react';
12
12
  import { decode, encode } from 'turbo-stream';
13
13
  import { parse, serialize } from 'cookie';
14
- import { streamMultipart } from '@web3-storage/multipart-parser';
15
14
  import { splitCookiesString } from 'set-cookie-parser';
16
15
 
17
- function _asyncIterator(iterable) {
18
- var method,
19
- async,
20
- sync,
21
- retry = 2;
22
- for ("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;) {
23
- if (async && null != (method = iterable[async])) return method.call(iterable);
24
- if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable));
25
- async = "@@asyncIterator", sync = "@@iterator";
26
- }
27
- throw new TypeError("Object is not async iterable");
28
- }
29
- function AsyncFromSyncIterator(s) {
30
- function AsyncFromSyncIteratorContinuation(r) {
31
- if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object."));
32
- var done = r.done;
33
- return Promise.resolve(r.value).then(function (value) {
34
- return {
35
- value: value,
36
- done: done
37
- };
38
- });
39
- }
40
- return AsyncFromSyncIterator = function (s) {
41
- this.s = s, this.n = s.next;
42
- }, AsyncFromSyncIterator.prototype = {
43
- s: null,
44
- n: null,
45
- next: function () {
46
- return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
47
- },
48
- return: function (value) {
49
- var ret = this.s.return;
50
- return void 0 === ret ? Promise.resolve({
51
- value: value,
52
- done: !0
53
- }) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments));
54
- },
55
- throw: function (value) {
56
- var thr = this.s.return;
57
- return void 0 === thr ? Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments));
58
- }
59
- }, new AsyncFromSyncIterator(s);
60
- }
61
16
  function _extends() {
62
17
  _extends = Object.assign ? Object.assign.bind() : function (target) {
63
18
  for (var i = 1; i < arguments.length; i++) {
@@ -3878,10 +3833,31 @@ function patchRoutesImpl(routeId, children, routesToUse, manifest, mapRoutePrope
3878
3833
  // Don't patch in routes we already know about so that `patch` is idempotent
3879
3834
  // to simplify user-land code. This is useful because we re-call the
3880
3835
  // `patchRoutesOnNavigation` function for matched routes with params.
3881
- let uniqueChildren = children.filter(a => !childrenToPatch.some(b => a.index === b.index && a.path === b.path && a.caseSensitive === b.caseSensitive));
3836
+ let uniqueChildren = children.filter(newRoute => !childrenToPatch.some(existingRoute => isSameRoute(newRoute, existingRoute)));
3882
3837
  let newRoutes = convertRoutesToDataRoutes(uniqueChildren, mapRouteProperties, [routeId || "_", "patch", String(((_childrenToPatch = childrenToPatch) == null ? void 0 : _childrenToPatch.length) || "0")], manifest);
3883
3838
  childrenToPatch.push(...newRoutes);
3884
3839
  }
3840
+ function isSameRoute(newRoute, existingRoute) {
3841
+ // Most optimal check is by id
3842
+ if ("id" in newRoute && "id" in existingRoute && newRoute.id === existingRoute.id) {
3843
+ return true;
3844
+ }
3845
+ // Second is by pathing differences
3846
+ if (!(newRoute.index === existingRoute.index && newRoute.path === existingRoute.path && newRoute.caseSensitive === existingRoute.caseSensitive)) {
3847
+ return false;
3848
+ }
3849
+ // Pathless layout routes are trickier since we need to check children.
3850
+ // If they have no children then they're the same as far as we can tell
3851
+ if ((!newRoute.children || newRoute.children.length === 0) && (!existingRoute.children || existingRoute.children.length === 0)) {
3852
+ return true;
3853
+ }
3854
+ // Otherwise, we look to see if every child in the new route is already
3855
+ // represented in the existing route's children
3856
+ return newRoute.children.every((aChild, i) => {
3857
+ var _existingRoute$childr;
3858
+ return (_existingRoute$childr = existingRoute.children) == null ? void 0 : _existingRoute$childr.some(bChild => isSameRoute(aChild, bChild));
3859
+ });
3860
+ }
3885
3861
  /**
3886
3862
  * Execute route.lazy() methods to lazily load route modules (loader, action,
3887
3863
  * shouldRevalidate) and update the routeManifest in place which shares objects
@@ -7249,6 +7225,11 @@ function singleFetchUrl(reqUrl) {
7249
7225
  }
7250
7226
  async function fetchAndDecode(url, init) {
7251
7227
  let res = await fetch(url, init);
7228
+ // If this 404'd without hitting the running server (most likely in a
7229
+ // pre-rendered app using a CDN), then bubble a standard 404 ErrorResponse
7230
+ if (res.status === 404 && !res.headers.has("X-Remix-Response")) {
7231
+ throw new ErrorResponseImpl(404, "Not Found", true);
7232
+ }
7252
7233
  !res.body ? process.env.NODE_ENV !== "production" ? invariant$1(false, "No response body to decode") : invariant$1(false) : void 0;
7253
7234
  try {
7254
7235
  let decoded = await decodeViaTurboStream(res.body, window);
@@ -10372,70 +10353,6 @@ function warnOnceAboutExpiresCookie(name, expires) {
10372
10353
  warnOnce(!expires, "The \"" + name + "\" cookie has an \"expires\" property set. " + "This will cause the expires value to not be updated when the session is committed. " + "Instead, you should set the expires value when serializing the cookie. " + "You can use `commitSession(session, { expires })` if using a session storage object, " + "or `cookie.serialize(\"value\", { expires })` if you're using the cookie directly.");
10373
10354
  }
10374
10355
 
10375
- function composeUploadHandlers() {
10376
- for (var _len = arguments.length, handlers = new Array(_len), _key = 0; _key < _len; _key++) {
10377
- handlers[_key] = arguments[_key];
10378
- }
10379
- return async part => {
10380
- for (let handler of handlers) {
10381
- let value = await handler(part);
10382
- if (typeof value !== "undefined" && value !== null) {
10383
- return value;
10384
- }
10385
- }
10386
- return undefined;
10387
- };
10388
- }
10389
- /**
10390
- * Allows you to handle multipart forms (file uploads) for your app.
10391
- *
10392
- * TODO: Update this comment
10393
- * @see https://remix.run/utils/parse-multipart-form-data
10394
- */
10395
- async function parseMultipartFormData(request, uploadHandler) {
10396
- let contentType = request.headers.get("Content-Type") || "";
10397
- let [type, boundary] = contentType.split(/\s*;\s*boundary=/);
10398
- if (!request.body || !boundary || type !== "multipart/form-data") {
10399
- throw new TypeError("Could not parse content as FormData.");
10400
- }
10401
- let formData = new FormData();
10402
- let parts = streamMultipart(request.body, boundary);
10403
- var _iteratorAbruptCompletion = false;
10404
- var _didIteratorError = false;
10405
- var _iteratorError;
10406
- try {
10407
- for (var _iterator = _asyncIterator(parts), _step; _iteratorAbruptCompletion = !(_step = await _iterator.next()).done; _iteratorAbruptCompletion = false) {
10408
- let part = _step.value;
10409
- {
10410
- if (part.done) break;
10411
- if (typeof part.filename === "string") {
10412
- // only pass basename as the multipart/form-data spec recommends
10413
- // https://datatracker.ietf.org/doc/html/rfc7578#section-4.2
10414
- part.filename = part.filename.split(/[/\\]/).pop();
10415
- }
10416
- let value = await uploadHandler(part);
10417
- if (typeof value !== "undefined" && value !== null) {
10418
- formData.append(part.name, value);
10419
- }
10420
- }
10421
- }
10422
- } catch (err) {
10423
- _didIteratorError = true;
10424
- _iteratorError = err;
10425
- } finally {
10426
- try {
10427
- if (_iteratorAbruptCompletion && _iterator.return != null) {
10428
- await _iterator.return();
10429
- }
10430
- } finally {
10431
- if (_didIteratorError) {
10432
- throw _iteratorError;
10433
- }
10434
- }
10435
- }
10436
- return formData;
10437
- }
10438
-
10439
10356
  function createEntryRouteModules(manifest) {
10440
10357
  return Object.keys(manifest).reduce((memo, routeId) => {
10441
10358
  memo[routeId] = manifest[routeId].module;
@@ -11618,74 +11535,6 @@ function createMemorySessionStorage(_temp) {
11618
11535
  });
11619
11536
  }
11620
11537
 
11621
- class MaxPartSizeExceededError extends Error {
11622
- constructor(field, maxBytes) {
11623
- super("Field \"" + field + "\" exceeded upload size of " + maxBytes + " bytes.");
11624
- this.field = field;
11625
- this.maxBytes = maxBytes;
11626
- }
11627
- }
11628
-
11629
- function createMemoryUploadHandler(_temp) {
11630
- let {
11631
- filter,
11632
- maxPartSize = 3000000
11633
- } = _temp === void 0 ? {} : _temp;
11634
- return async _ref => {
11635
- let {
11636
- filename,
11637
- contentType,
11638
- name,
11639
- data
11640
- } = _ref;
11641
- if (filter && !(await filter({
11642
- filename,
11643
- contentType,
11644
- name
11645
- }))) {
11646
- return undefined;
11647
- }
11648
- let size = 0;
11649
- let chunks = [];
11650
- var _iteratorAbruptCompletion = false;
11651
- var _didIteratorError = false;
11652
- var _iteratorError;
11653
- try {
11654
- for (var _iterator = _asyncIterator(data), _step; _iteratorAbruptCompletion = !(_step = await _iterator.next()).done; _iteratorAbruptCompletion = false) {
11655
- let chunk = _step.value;
11656
- {
11657
- size += chunk.byteLength;
11658
- if (size > maxPartSize) {
11659
- throw new MaxPartSizeExceededError(name, maxPartSize);
11660
- }
11661
- chunks.push(chunk);
11662
- }
11663
- }
11664
- } catch (err) {
11665
- _didIteratorError = true;
11666
- _iteratorError = err;
11667
- } finally {
11668
- try {
11669
- if (_iteratorAbruptCompletion && _iterator.return != null) {
11670
- await _iterator.return();
11671
- }
11672
- } finally {
11673
- if (_didIteratorError) {
11674
- throw _iteratorError;
11675
- }
11676
- }
11677
- }
11678
- if (typeof filename === "string") {
11679
- return new File(chunks, filename, {
11680
- type: contentType
11681
- });
11682
- }
11683
- return await new Blob(chunks, {
11684
- type: contentType
11685
- }).text();
11686
- };
11687
- }
11688
-
11689
11538
  function deserializeErrors(errors) {
11690
11539
  if (!errors) return null;
11691
11540
  let entries = Object.entries(errors);
@@ -11722,5 +11571,5 @@ function deserializeErrors(errors) {
11722
11571
  return serialized;
11723
11572
  }
11724
11573
 
11725
- export { Await, BrowserRouter, Form, HashRouter, IDLE_BLOCKER, IDLE_FETCHER, IDLE_NAVIGATION, Link, Links, MaxPartSizeExceededError, MemoryRouter, Meta, NavLink, Navigate, Action as NavigationType, Outlet, PrefetchPageLinks, Route, Router, RouterProvider, Routes, Scripts, ScrollRestoration, ServerRouter, StaticRouter, StaticRouterProvider, DataRouterContext as UNSAFE_DataRouterContext, DataRouterStateContext as UNSAFE_DataRouterStateContext, ErrorResponseImpl as UNSAFE_ErrorResponseImpl, FetchersContext as UNSAFE_FetchersContext, FrameworkContext as UNSAFE_FrameworkContext, LocationContext as UNSAFE_LocationContext, NavigationContext as UNSAFE_NavigationContext, RemixErrorBoundary as UNSAFE_RemixErrorBoundary, RouteContext as UNSAFE_RouteContext, ServerMode as UNSAFE_ServerMode, SingleFetchRedirectSymbol as UNSAFE_SingleFetchRedirectSymbol, ViewTransitionContext as UNSAFE_ViewTransitionContext, createBrowserHistory as UNSAFE_createBrowserHistory, createClientRoutes as UNSAFE_createClientRoutes, createClientRoutesWithHMRRevalidationOptOut as UNSAFE_createClientRoutesWithHMRRevalidationOptOut, createRouter as UNSAFE_createRouter, decodeViaTurboStream as UNSAFE_decodeViaTurboStream, deserializeErrors as UNSAFE_deserializeErrors, getPatchRoutesOnNavigationFunction as UNSAFE_getPatchRoutesOnNavigationFunction, getSingleFetchDataStrategy$1 as UNSAFE_getSingleFetchDataStrategy, invariant$2 as UNSAFE_invariant, mapRouteProperties as UNSAFE_mapRouteProperties, shouldHydrateRouteLoader as UNSAFE_shouldHydrateRouteLoader, useFogOFWarDiscovery as UNSAFE_useFogOFWarDiscovery, useScrollRestoration as UNSAFE_useScrollRestoration, createBrowserRouter, createCookie, createCookieSessionStorage, createHashRouter, createMemoryRouter, createMemorySessionStorage, createPath, createRequestHandler, createRoutesFromChildren, createRoutesFromChildren as createRoutesFromElements, createRoutesStub, createSearchParams, createSession, createSessionStorage, createStaticHandler, createStaticRouter, data, generatePath, isCookie, isRouteErrorResponse, isSession, json$1 as json, matchPath, matchRoutes, parsePath, redirect, redirectDocument, renderMatches, replace, resolvePath, HistoryRouter as unstable_HistoryRouter, composeUploadHandlers as unstable_composeUploadHandlers, createMemoryUploadHandler as unstable_createMemoryUploadHandler, parseMultipartFormData as unstable_parseMultipartFormData, setDevServerHooks as unstable_setDevServerHooks, usePrompt as unstable_usePrompt, useActionData, useAsyncError, useAsyncValue, useBeforeUnload, useBlocker, useFetcher, useFetchers, useFormAction, useHref, useInRouterContext, useLinkClickHandler, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes, useSearchParams, useSubmit, useViewTransitionState };
11574
+ export { Await, BrowserRouter, Form, HashRouter, IDLE_BLOCKER, IDLE_FETCHER, IDLE_NAVIGATION, Link, Links, MemoryRouter, Meta, NavLink, Navigate, Action as NavigationType, Outlet, PrefetchPageLinks, Route, Router, RouterProvider, Routes, Scripts, ScrollRestoration, ServerRouter, StaticRouter, StaticRouterProvider, DataRouterContext as UNSAFE_DataRouterContext, DataRouterStateContext as UNSAFE_DataRouterStateContext, ErrorResponseImpl as UNSAFE_ErrorResponseImpl, FetchersContext as UNSAFE_FetchersContext, FrameworkContext as UNSAFE_FrameworkContext, LocationContext as UNSAFE_LocationContext, NavigationContext as UNSAFE_NavigationContext, RemixErrorBoundary as UNSAFE_RemixErrorBoundary, RouteContext as UNSAFE_RouteContext, ServerMode as UNSAFE_ServerMode, SingleFetchRedirectSymbol as UNSAFE_SingleFetchRedirectSymbol, ViewTransitionContext as UNSAFE_ViewTransitionContext, createBrowserHistory as UNSAFE_createBrowserHistory, createClientRoutes as UNSAFE_createClientRoutes, createClientRoutesWithHMRRevalidationOptOut as UNSAFE_createClientRoutesWithHMRRevalidationOptOut, createRouter as UNSAFE_createRouter, decodeViaTurboStream as UNSAFE_decodeViaTurboStream, deserializeErrors as UNSAFE_deserializeErrors, getPatchRoutesOnNavigationFunction as UNSAFE_getPatchRoutesOnNavigationFunction, getSingleFetchDataStrategy$1 as UNSAFE_getSingleFetchDataStrategy, invariant$2 as UNSAFE_invariant, mapRouteProperties as UNSAFE_mapRouteProperties, shouldHydrateRouteLoader as UNSAFE_shouldHydrateRouteLoader, useFogOFWarDiscovery as UNSAFE_useFogOFWarDiscovery, useScrollRestoration as UNSAFE_useScrollRestoration, createBrowserRouter, createCookie, createCookieSessionStorage, createHashRouter, createMemoryRouter, createMemorySessionStorage, createPath, createRequestHandler, createRoutesFromChildren, createRoutesFromChildren as createRoutesFromElements, createRoutesStub, createSearchParams, createSession, createSessionStorage, createStaticHandler, createStaticRouter, data, generatePath, isCookie, isRouteErrorResponse, isSession, json$1 as json, matchPath, matchRoutes, parsePath, redirect, redirectDocument, renderMatches, replace, resolvePath, HistoryRouter as unstable_HistoryRouter, setDevServerHooks as unstable_setDevServerHooks, usePrompt as unstable_usePrompt, useActionData, useAsyncError, useAsyncValue, useBeforeUnload, useBlocker, useFetcher, useFetchers, useFormAction, useHref, useInRouterContext, useLinkClickHandler, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes, useSearchParams, useSubmit, useViewTransitionState };
11726
11575
  //# sourceMappingURL=index.mjs.map