react-router 6.7.0-pre.1 → 6.7.0-pre.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # `react-router`
2
2
 
3
+ ## 6.7.0-pre.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies:
8
+ - `@remix-run/router@1.3.0-pre.2`
9
+
10
+ ## 6.7.0-pre.2
11
+
12
+ ### Patch Changes
13
+
14
+ - update <Await> to accept ReactNode as children function return result ([#9896](https://github.com/remix-run/react-router/pull/9896))
15
+
3
16
  ## 6.7.0-pre.1
4
17
 
5
18
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,16 +1,16 @@
1
- import type { ActionFunction, ActionFunctionArgs, Fetcher, HydrationState, JsonFunction, LoaderFunction, LoaderFunctionArgs, Location, Navigation, Params, ParamParseKey, Path, PathMatch, PathPattern, RedirectFunction, Router as RemixRouter, ShouldRevalidateFunction, To, InitialEntry } from "@remix-run/router";
1
+ import type { ActionFunction, ActionFunctionArgs, Blocker, BlockerFunction, Fetcher, HydrationState, JsonFunction, LoaderFunction, LoaderFunctionArgs, Location, Navigation, Params, ParamParseKey, Path, PathMatch, PathPattern, RedirectFunction, Router as RemixRouter, ShouldRevalidateFunction, To, InitialEntry } from "@remix-run/router";
2
2
  import { AbortedDeferredError, Action as NavigationType, createPath, defer, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, resolvePath } from "@remix-run/router";
3
3
  import type { AwaitProps, MemoryRouterProps, NavigateProps, OutletProps, RouteProps, PathRouteProps, LayoutRouteProps, IndexRouteProps, RouterProps, RoutesProps, RouterProviderProps } from "./lib/components";
4
4
  import { enhanceManualRouteObjects, createRoutesFromChildren, renderMatches, Await, MemoryRouter, Navigate, Outlet, Route, Router, RouterProvider, Routes } from "./lib/components";
5
5
  import type { DataRouteMatch, DataRouteObject, IndexRouteObject, Navigator, NavigateOptions, NonIndexRouteObject, RouteMatch, RouteObject, RelativeRoutingType } from "./lib/context";
6
6
  import { DataRouterContext, DataRouterStateContext, LocationContext, NavigationContext, RouteContext } from "./lib/context";
7
7
  import type { NavigateFunction } from "./lib/hooks";
8
- import { useHref, useInRouterContext, useLocation, useMatch, useNavigationType, useNavigate, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes, useActionData, useAsyncError, useAsyncValue, useLoaderData, useMatches, useNavigation, useRevalidator, useRouteError, useRouteLoaderData } from "./lib/hooks";
8
+ import { useBlocker, useHref, useInRouterContext, useLocation, useMatch, useNavigationType, useNavigate, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes, useActionData, useAsyncError, useAsyncValue, useLoaderData, useMatches, useNavigation, useRevalidator, useRouteError, useRouteLoaderData } from "./lib/hooks";
9
9
  declare type Hash = string;
10
10
  declare type Pathname = string;
11
11
  declare type Search = string;
12
- export type { ActionFunction, ActionFunctionArgs, AwaitProps, DataRouteMatch, DataRouteObject, Fetcher, Hash, IndexRouteObject, IndexRouteProps, JsonFunction, LayoutRouteProps, LoaderFunction, LoaderFunctionArgs, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, NonIndexRouteObject, OutletProps, Params, ParamParseKey, Path, PathMatch, Pathname, PathPattern, PathRouteProps, RedirectFunction, RelativeRoutingType, RouteMatch, RouteObject, RouteProps, RouterProps, RouterProviderProps, RoutesProps, Search, ShouldRevalidateFunction, To, };
13
- export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, RouterProvider, Routes, createPath, createRoutesFromChildren, createRoutesFromChildren as createRoutesFromElements, defer, isRouteErrorResponse, generatePath, json, matchPath, matchRoutes, parsePath, redirect, renderMatches, resolvePath, useActionData, useAsyncError, useAsyncValue, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes, };
12
+ export type { ActionFunction, ActionFunctionArgs, AwaitProps, Blocker as unstable_Blocker, BlockerFunction as unstable_BlockerFunction, DataRouteMatch, DataRouteObject, Fetcher, Hash, IndexRouteObject, IndexRouteProps, JsonFunction, LayoutRouteProps, LoaderFunction, LoaderFunctionArgs, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, NonIndexRouteObject, OutletProps, Params, ParamParseKey, Path, PathMatch, Pathname, PathPattern, PathRouteProps, RedirectFunction, RelativeRoutingType, RouteMatch, RouteObject, RouteProps, RouterProps, RouterProviderProps, RoutesProps, Search, ShouldRevalidateFunction, To, };
13
+ export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, RouterProvider, Routes, createPath, createRoutesFromChildren, createRoutesFromChildren as createRoutesFromElements, defer, isRouteErrorResponse, generatePath, json, matchPath, matchRoutes, parsePath, redirect, renderMatches, resolvePath, useActionData, useAsyncError, useAsyncValue, useBlocker as unstable_useBlocker, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes, };
14
14
  export declare function createMemoryRouter(routes: RouteObject[], opts?: {
15
15
  basename?: string;
16
16
  hydrationData?: HydrationState;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * React Router v6.7.0-pre.1
2
+ * React Router v6.7.0-pre.3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -722,6 +722,7 @@ function _renderMatches(matches, parentMatches, dataRouterState) {
722
722
  var DataRouterHook;
723
723
 
724
724
  (function (DataRouterHook) {
725
+ DataRouterHook["UseBlocker"] = "useBlocker";
725
726
  DataRouterHook["UseRevalidator"] = "useRevalidator";
726
727
  })(DataRouterHook || (DataRouterHook = {}));
727
728
 
@@ -884,6 +885,28 @@ function useAsyncValue() {
884
885
  function useAsyncError() {
885
886
  let value = React.useContext(AwaitContext);
886
887
  return value == null ? void 0 : value._error;
888
+ } // useBlocker() is a singleton for now since we don't have any compelling use
889
+ // cases for multi-blocker yet
890
+
891
+ let blockerKey = "blocker-singleton";
892
+ /**
893
+ * Allow the application to block navigations within the SPA and present the
894
+ * user a confirmation dialog to confirm the navigation. Mostly used to avoid
895
+ * using half-filled form data. This does not handle hard-reloads or
896
+ * cross-origin navigations.
897
+ */
898
+
899
+ function useBlocker(shouldBlock) {
900
+ let {
901
+ router
902
+ } = useDataRouterContext(DataRouterHook.UseBlocker);
903
+ let blockerFunction = React.useCallback(args => {
904
+ return typeof shouldBlock === "function" ? !!shouldBlock(args) : !!shouldBlock;
905
+ }, [shouldBlock]);
906
+ let blocker = router.getBlocker(blockerKey, blockerFunction); // Cleanup on unmount
907
+
908
+ React.useEffect(() => () => router.deleteBlocker(blockerKey), [router]);
909
+ return blocker;
887
910
  }
888
911
  const alreadyWarned = {};
889
912
 
@@ -1265,12 +1288,8 @@ function ResolveAwait(_ref7) {
1265
1288
  children
1266
1289
  } = _ref7;
1267
1290
  let data = useAsyncValue();
1268
-
1269
- if (typeof children === "function") {
1270
- return children(data);
1271
- }
1272
-
1273
- return /*#__PURE__*/React.createElement(React.Fragment, null, children);
1291
+ let toRender = typeof children === "function" ? children(data) : children;
1292
+ return /*#__PURE__*/React.createElement(React.Fragment, null, toRender);
1274
1293
  } ///////////////////////////////////////////////////////////////////////////////
1275
1294
  // UTILS
1276
1295
  ///////////////////////////////////////////////////////////////////////////////
@@ -1369,5 +1388,5 @@ function createMemoryRouter(routes, opts) {
1369
1388
  }).initialize();
1370
1389
  } ///////////////////////////////////////////////////////////////////////////////
1371
1390
 
1372
- export { Await, MemoryRouter, Navigate, Outlet, Route, Router, RouterProvider, Routes, DataRouterContext as UNSAFE_DataRouterContext, DataRouterStateContext as UNSAFE_DataRouterStateContext, LocationContext as UNSAFE_LocationContext, NavigationContext as UNSAFE_NavigationContext, RouteContext as UNSAFE_RouteContext, enhanceManualRouteObjects as UNSAFE_enhanceManualRouteObjects, createMemoryRouter, createRoutesFromChildren, createRoutesFromChildren as createRoutesFromElements, renderMatches, useActionData, useAsyncError, useAsyncValue, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes };
1391
+ export { Await, MemoryRouter, Navigate, Outlet, Route, Router, RouterProvider, Routes, DataRouterContext as UNSAFE_DataRouterContext, DataRouterStateContext as UNSAFE_DataRouterStateContext, LocationContext as UNSAFE_LocationContext, NavigationContext as UNSAFE_NavigationContext, RouteContext as UNSAFE_RouteContext, enhanceManualRouteObjects as UNSAFE_enhanceManualRouteObjects, createMemoryRouter, createRoutesFromChildren, createRoutesFromChildren as createRoutesFromElements, renderMatches, useBlocker as unstable_useBlocker, useActionData, useAsyncError, useAsyncValue, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes };
1373
1392
  //# sourceMappingURL=index.js.map