react-router 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.
@@ -2,24 +2,13 @@ import type { InitialEntry, LazyRouteFunction, Location, RelativeRoutingType, Ro
2
2
  import { Action as NavigationType } from "@remix-run/router";
3
3
  import * as React from "react";
4
4
  import type { IndexRouteObject, Navigator, NonIndexRouteObject, RouteMatch, RouteObject } from "./context";
5
- interface ViewTransition {
6
- finished: Promise<void>;
7
- ready: Promise<void>;
8
- updateCallbackDone: Promise<void>;
9
- skipTransition(): void;
10
- }
11
- declare global {
12
- interface Document {
13
- startViewTransition(cb: () => Promise<void> | void): ViewTransition;
14
- }
15
- }
16
5
  export interface FutureConfig {
17
6
  v7_startTransition: boolean;
18
7
  }
19
8
  export interface RouterProviderProps {
20
9
  fallbackElement?: React.ReactNode;
21
10
  router: RemixRouter;
22
- future?: FutureConfig;
11
+ future?: Partial<FutureConfig>;
23
12
  }
24
13
  /**
25
14
  * Given a Remix Router instance, render the appropriate UI
@@ -160,4 +149,3 @@ export declare function createRoutesFromChildren(children: React.ReactNode, pare
160
149
  * Renders the result of `matchRoutes()` into a React element.
161
150
  */
162
151
  export declare function renderMatches(matches: RouteMatch[] | null): React.ReactElement | null;
163
- export {};
@@ -49,14 +49,6 @@ export interface DataRouterContextObject extends NavigationContextObject {
49
49
  }
50
50
  export declare const DataRouterContext: React.Context<DataRouterContextObject | null>;
51
51
  export declare const DataRouterStateContext: React.Context<import("@remix-run/router").RouterState | null>;
52
- export type ViewTransitionContextObject = {
53
- isTransitioning: false;
54
- } | {
55
- isTransitioning: true;
56
- currentLocation: Location;
57
- nextLocation: Location;
58
- };
59
- export declare const ViewTransitionContext: React.Context<ViewTransitionContextObject>;
60
52
  export declare const AwaitContext: React.Context<TrackedPromise | null>;
61
53
  export interface NavigateOptions {
62
54
  replace?: boolean;
package/dist/main.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * React Router v0.0.0-experimental-4a8a492a
2
+ * React Router v0.0.0-experimental-e0f088aa
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * React Router v0.0.0-experimental-4a8a492a
2
+ * React Router v0.0.0-experimental-e0f088aa
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -20,12 +20,6 @@ const DataRouterStateContext = /*#__PURE__*/React.createContext(null);
20
20
  {
21
21
  DataRouterStateContext.displayName = "DataRouterState";
22
22
  }
23
- const ViewTransitionContext = /*#__PURE__*/React.createContext({
24
- isTransitioning: false
25
- });
26
- {
27
- ViewTransitionContext.displayName = "ViewTransition";
28
- }
29
23
  const AwaitContext = /*#__PURE__*/React.createContext(null);
30
24
  {
31
25
  AwaitContext.displayName = "Await";
@@ -791,32 +785,6 @@ function warningOnce(key, cond, message) {
791
785
  */
792
786
  const START_TRANSITION = "startTransition";
793
787
  const startTransitionImpl = React[START_TRANSITION];
794
- function startTransitionSafe(cb) {
795
- if (startTransitionImpl) {
796
- startTransitionImpl(cb);
797
- } else {
798
- cb();
799
- }
800
- }
801
- class Deferred {
802
- constructor() {
803
- this.status = "pending";
804
- this.promise = new Promise((resolve, reject) => {
805
- this.resolve = value => {
806
- if (this.status === "pending") {
807
- this.status = "resolved";
808
- resolve(value);
809
- }
810
- };
811
- this.reject = reason => {
812
- if (this.status === "pending") {
813
- this.status = "rejected";
814
- reject(reason);
815
- }
816
- };
817
- });
818
- }
819
- }
820
788
  /**
821
789
  * Given a Remix Router instance, render the appropriate UI
822
790
  */
@@ -826,101 +794,19 @@ function RouterProvider({
826
794
  future
827
795
  }) {
828
796
  let [state, setStateImpl] = React.useState(router.state);
829
- let [pendingState, setPendingState] = React.useState();
830
- let [vtContext, setVtContext] = React.useState({
831
- isTransitioning: false
832
- });
833
- let [renderDfd, setRenderDfd] = React.useState();
834
- let [transition, setTransition] = React.useState();
835
- let [interruption, setInterruption] = React.useState();
836
797
  let {
837
798
  v7_startTransition
838
799
  } = future || {};
839
- let optInStartTransition = React.useCallback(cb => {
840
- if (v7_startTransition) {
841
- startTransitionSafe(cb);
842
- } else {
843
- cb();
844
- }
845
- }, [v7_startTransition]);
846
- let setState = React.useCallback((newState, {
847
- viewTransitionOpts
848
- }) => {
849
- if (!viewTransitionOpts || typeof document.startViewTransition !== "function") {
850
- // Mid-navigation state update, or startViewTransition isn't available
851
- optInStartTransition(() => setStateImpl(newState));
852
- } else if (transition && renderDfd) {
853
- // Interrupting an in-progress transition, cancel and let everything flush
854
- // out, and then kick off a new transition from the interruption state
855
- renderDfd.resolve();
856
- transition.skipTransition();
857
- setInterruption({
858
- state: newState,
859
- currentLocation: viewTransitionOpts.currentLocation,
860
- nextLocation: viewTransitionOpts.nextLocation
861
- });
800
+ let setState = React.useCallback(newState => {
801
+ if (v7_startTransition && startTransitionImpl) {
802
+ startTransitionImpl(() => setStateImpl(newState));
862
803
  } else {
863
- // Completed navigation update with opted-in view transitions, let 'er rip
864
- setPendingState(newState);
865
- setVtContext({
866
- isTransitioning: true,
867
- currentLocation: viewTransitionOpts.currentLocation,
868
- nextLocation: viewTransitionOpts.nextLocation
869
- });
804
+ setStateImpl(newState);
870
805
  }
871
- }, [optInStartTransition, transition, renderDfd]);
806
+ }, [setStateImpl, v7_startTransition]);
872
807
  // Need to use a layout effect here so we are subscribed early enough to
873
808
  // pick up on any render-driven redirects/navigations (useEffect/<Navigate>)
874
809
  React.useLayoutEffect(() => router.subscribe(setState), [router, setState]);
875
- // When we start a view transition, create a Deferred we can use for the
876
- // eventual "completed" render
877
- React.useEffect(() => {
878
- if (vtContext.isTransitioning) {
879
- setRenderDfd(new Deferred());
880
- }
881
- }, [vtContext.isTransitioning]);
882
- // Once the deferred is created, kick off startViewTransition() to update the
883
- // DOM and then wait on the Deferred to resolve (indicating the DOM update has
884
- // happened)
885
- React.useEffect(() => {
886
- if (renderDfd && pendingState) {
887
- let newState = pendingState;
888
- let renderPromise = renderDfd.promise;
889
- let transition = document.startViewTransition(async () => {
890
- optInStartTransition(() => setStateImpl(newState));
891
- await renderPromise;
892
- });
893
- transition.finished.finally(() => {
894
- setRenderDfd(undefined);
895
- setTransition(undefined);
896
- setPendingState(undefined);
897
- setVtContext({
898
- isTransitioning: false
899
- });
900
- });
901
- setTransition(transition);
902
- }
903
- }, [optInStartTransition, pendingState, renderDfd]);
904
- // When the new location finally renders and is committed to the DOM, this
905
- // effect will run to resolve the transition
906
- React.useEffect(() => {
907
- if (renderDfd && pendingState && state.location.key === pendingState.location.key) {
908
- renderDfd.resolve();
909
- }
910
- }, [renderDfd, transition, state.location, pendingState]);
911
- // If we get interrupted with a new navigation during a transition, we skip
912
- // the active transition, let it cleanup, then kick it off again here
913
- React.useEffect(() => {
914
- if (!vtContext.isTransitioning && interruption) {
915
- setPendingState(interruption.state);
916
- setVtContext({
917
- isTransitioning: true,
918
- currentLocation: interruption.currentLocation,
919
- nextLocation: interruption.nextLocation
920
- });
921
- setInterruption(undefined);
922
- }
923
- }, [vtContext.isTransitioning, interruption]);
924
810
  let navigator = React.useMemo(() => {
925
811
  return {
926
812
  createHref: router.createHref,
@@ -954,8 +840,6 @@ function RouterProvider({
954
840
  value: dataRouterContext
955
841
  }, /*#__PURE__*/React.createElement(DataRouterStateContext.Provider, {
956
842
  value: state
957
- }, /*#__PURE__*/React.createElement(ViewTransitionContext.Provider, {
958
- value: vtContext
959
843
  }, /*#__PURE__*/React.createElement(Router, {
960
844
  basename: basename,
961
845
  location: state.location,
@@ -964,7 +848,7 @@ function RouterProvider({
964
848
  }, state.initialized ? /*#__PURE__*/React.createElement(DataRoutes, {
965
849
  routes: router.routes,
966
850
  state: state
967
- }) : fallbackElement)))), null);
851
+ }) : fallbackElement))), null);
968
852
  }
969
853
  function DataRoutes({
970
854
  routes,
@@ -1362,5 +1246,5 @@ function createMemoryRouter(routes, opts) {
1362
1246
  }).initialize();
1363
1247
  }
1364
1248
 
1365
- 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, ViewTransitionContext as UNSAFE_ViewTransitionContext, mapRouteProperties as UNSAFE_mapRouteProperties, useRouteId as UNSAFE_useRouteId, useRoutesImpl as UNSAFE_useRoutesImpl, 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 };
1249
+ 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, mapRouteProperties as UNSAFE_mapRouteProperties, useRouteId as UNSAFE_useRouteId, useRoutesImpl as UNSAFE_useRoutesImpl, 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 };
1366
1250
  //# sourceMappingURL=react-router.development.js.map