react-router-dom 0.0.0-experimental-4a8a492a → 0.0.0-experimental-e0f088aa

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,59 @@
1
1
  # `react-router-dom`
2
2
 
3
+ ## 6.17.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Add experimental support for the [View Transitions API](https://developer.mozilla.org/en-US/docs/Web/API/ViewTransition) via `document.startViewTransition` to enable CSS animated transitions on SPA navigations in your application. ([#10916](https://github.com/remix-run/react-router/pull/10916))
8
+
9
+ The simplest approach to enabling a View Transition in your React Router app is via the new `<Link unstable_viewTransition>` prop. This will cause the navigation DOM update to be wrapped in `document.startViewTransition` which will enable transitions for the DOM update. Without any additional CSS styles, you'll get a basic cross-fade animation for your page.
10
+
11
+ If you need to apply more fine-grained styles for your animations, you can leverage the `unstable_useViewTransitionState` hook which will tell you when a transition is in progress and you can use that to apply classes or styles:
12
+
13
+ ```jsx
14
+ function ImageLink(to, src, alt) {
15
+ let isTransitioning = unstable_useViewTransitionState(to);
16
+ return (
17
+ <Link to={to} unstable_viewTransition>
18
+ <img
19
+ src={src}
20
+ alt={alt}
21
+ style={{
22
+ viewTransitionName: isTransitioning ? "image-expand" : "",
23
+ }}
24
+ />
25
+ </Link>
26
+ );
27
+ }
28
+ ```
29
+
30
+ You can also use the `<NavLink unstable_viewTransition>` shorthand which will manage the hook usage for you and automatically add a `transitioning` class to the `<a>` during the transition:
31
+
32
+ ```css
33
+ a.transitioning img {
34
+ view-transition-name: "image-expand";
35
+ }
36
+ ```
37
+
38
+ ```jsx
39
+ <NavLink to={to} unstable_viewTransition>
40
+ <img src={src} alt={alt} />
41
+ </NavLink>
42
+ ```
43
+
44
+ For an example usage of View Transitions with React Router, check out [our fork](https://github.com/brophdawg11/react-router-records) of the [Astro Records](https://github.com/Charca/astro-records) demo.
45
+
46
+ For more information on using the View Transitions API, please refer to the [Smooth and simple transitions with the View Transitions API](https://developer.chrome.com/docs/web-platform/view-transitions/) guide from the Google Chrome team.
47
+
48
+ Please note, that because the `ViewTransition` API is a DOM API, we now export a specific `RouterProvider` from `react-router-dom` with this functionality. If you are importing `RouterProvider` from `react-router`, then it will not support view transitions. ([#10928](https://github.com/remix-run/react-router/pull/10928)
49
+
50
+ ### Patch Changes
51
+
52
+ - Log a warning and fail gracefully in `ScrollRestoration` when `sessionStorage` is unavailable ([#10848](https://github.com/remix-run/react-router/pull/10848))
53
+ - Updated dependencies:
54
+ - `@remix-run/router@1.10.0`
55
+ - `react-router@6.17.0`
56
+
3
57
  ## 6.16.0
4
58
 
5
59
  ### Minor Changes
package/dist/dom.d.ts CHANGED
@@ -56,6 +56,14 @@ export interface SubmitOptions {
56
56
  * Defaults to "application/x-www-form-urlencoded".
57
57
  */
58
58
  encType?: FormEncType;
59
+ /**
60
+ * Indicate a specific fetcherKey to use when using navigate=false
61
+ */
62
+ fetcherKey?: string;
63
+ /**
64
+ * navigate=false will use a fetcher instead of a navigation
65
+ */
66
+ navigate?: boolean;
59
67
  /**
60
68
  * Set `true` to replace the current entry in the browser's history stack
61
69
  * instead of creating a new one (i.e. stay on "the same page"). Defaults
package/dist/index.d.ts CHANGED
@@ -3,18 +3,21 @@
3
3
  * you'll need to update the rollup config for react-router-dom-v5-compat.
4
4
  */
5
5
  import * as React from "react";
6
- import type { FutureConfig, NavigateOptions, RelativeRoutingType, RouteObject, To } from "react-router";
6
+ import type { FutureConfig, Location, NavigateOptions, RelativeRoutingType, RouteObject, RouterProviderProps, To } from "react-router";
7
7
  import type { Fetcher, FormEncType, FormMethod, FutureConfig as RouterFutureConfig, GetScrollRestorationKeyFunction, History, HTMLFormMethod, HydrationState, Router as RemixRouter, V7_FormMethod } from "@remix-run/router";
8
8
  import type { SubmitOptions, ParamKeyValuePair, URLSearchParamsInit, SubmitTarget } from "./dom";
9
9
  import { createSearchParams } from "./dom";
10
10
  export type { FormEncType, FormMethod, GetScrollRestorationKeyFunction, ParamKeyValuePair, SubmitOptions, URLSearchParamsInit, V7_FormMethod, };
11
11
  export { createSearchParams };
12
12
  export type { ActionFunction, ActionFunctionArgs, AwaitProps, unstable_Blocker, unstable_BlockerFunction, DataRouteMatch, DataRouteObject, ErrorResponse, Fetcher, Hash, IndexRouteObject, IndexRouteProps, JsonFunction, LazyRouteFunction, 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, ShouldRevalidateFunctionArgs, To, UIMatch, } from "react-router";
13
- export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, RouterProvider, Routes, createMemoryRouter, createPath, createRoutesFromChildren, createRoutesFromElements, defer, isRouteErrorResponse, generatePath, json, matchPath, matchRoutes, parsePath, redirect, redirectDocument, renderMatches, resolvePath, useActionData, useAsyncError, useAsyncValue, unstable_useBlocker, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes, } from "react-router";
13
+ export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, Routes, createMemoryRouter, createPath, createRoutesFromChildren, createRoutesFromElements, defer, isRouteErrorResponse, generatePath, json, matchPath, matchRoutes, parsePath, redirect, redirectDocument, renderMatches, resolvePath, useActionData, useAsyncError, useAsyncValue, unstable_useBlocker, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes, } from "react-router";
14
14
  /** @internal */
15
- export { UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_NavigationContext, UNSAFE_LocationContext, UNSAFE_RouteContext, UNSAFE_ViewTransitionContext, UNSAFE_useRouteId, } from "react-router";
15
+ export { UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_NavigationContext, UNSAFE_LocationContext, UNSAFE_RouteContext, UNSAFE_useRouteId, } from "react-router";
16
16
  declare global {
17
17
  var __staticRouterHydrationData: HydrationState | undefined;
18
+ interface Document {
19
+ startViewTransition(cb: () => Promise<void> | void): ViewTransition;
20
+ }
18
21
  }
19
22
  interface DOMRouterOpts {
20
23
  basename?: string;
@@ -24,6 +27,32 @@ interface DOMRouterOpts {
24
27
  }
25
28
  export declare function createBrowserRouter(routes: RouteObject[], opts?: DOMRouterOpts): RemixRouter;
26
29
  export declare function createHashRouter(routes: RouteObject[], opts?: DOMRouterOpts): RemixRouter;
30
+ type ViewTransitionContextObject = {
31
+ isTransitioning: false;
32
+ } | {
33
+ isTransitioning: true;
34
+ currentLocation: Location;
35
+ nextLocation: Location;
36
+ };
37
+ declare const ViewTransitionContext: React.Context<ViewTransitionContextObject>;
38
+ export { ViewTransitionContext as UNSAFE_ViewTransitionContext };
39
+ type FetchersContextObject = {
40
+ data: Map<string, any>;
41
+ register: (key: string) => void;
42
+ unregister: (key: string) => void;
43
+ };
44
+ declare const FetchersContext: React.Context<FetchersContextObject | null>;
45
+ export { FetchersContext as UNSAFE_FetchersContext };
46
+ interface ViewTransition {
47
+ finished: Promise<void>;
48
+ ready: Promise<void>;
49
+ updateCallbackDone: Promise<void>;
50
+ skipTransition(): void;
51
+ }
52
+ /**
53
+ * Given a Remix Router instance, render the appropriate UI
54
+ */
55
+ export declare function RouterProvider({ fallbackElement, router, future, }: RouterProviderProps): React.ReactElement;
27
56
  export interface BrowserRouterProps {
28
57
  basename?: string;
29
58
  children?: React.ReactNode;
@@ -125,6 +154,14 @@ export interface FetcherFormProps extends React.FormHTMLAttributes<HTMLFormEleme
125
154
  onSubmit?: React.FormEventHandler<HTMLFormElement>;
126
155
  }
127
156
  export interface FormProps extends FetcherFormProps {
157
+ /**
158
+ * Indicate a specific fetcherKey to use when using navigate=false
159
+ */
160
+ fetcherKey?: string;
161
+ /**
162
+ * navigate=false will use a fetcher instead of a navigation
163
+ */
164
+ navigate?: boolean;
128
165
  /**
129
166
  * Forces a full document navigation instead of a fetch.
130
167
  */
@@ -216,9 +253,8 @@ export declare function useSubmit(): SubmitFunction;
216
253
  export declare function useFormAction(action?: string, { relative }?: {
217
254
  relative?: RelativeRoutingType;
218
255
  }): string;
219
- declare function createFetcherForm(fetcherKey: string, routeId: string): React.ForwardRefExoticComponent<FetcherFormProps & React.RefAttributes<HTMLFormElement>>;
220
256
  export type FetcherWithComponents<TData> = Fetcher<TData> & {
221
- Form: ReturnType<typeof createFetcherForm>;
257
+ Form: React.ForwardRefExoticComponent<FetcherFormProps & React.RefAttributes<HTMLFormElement>>;
222
258
  submit: FetcherSubmitFunction;
223
259
  load: (href: string) => void;
224
260
  };
@@ -226,7 +262,9 @@ export type FetcherWithComponents<TData> = Fetcher<TData> & {
226
262
  * Interacts with route loaders and actions without causing a navigation. Great
227
263
  * for any interaction that stays on the same page.
228
264
  */
229
- export declare function useFetcher<TData = any>(): FetcherWithComponents<TData>;
265
+ export declare function useFetcher<TData = any>({ key, }?: {
266
+ key?: string;
267
+ }): FetcherWithComponents<TData>;
230
268
  /**
231
269
  * Provides all fetchers currently on the page. Useful for layouts and parent
232
270
  * routes that need to provide pending/optimistic UI regarding the fetch.