Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

startViewTransition updates #10928

Merged
merged 8 commits into from
Oct 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add ViewTransitionContext to SSR for useId stability
  • Loading branch information
brophdawg11 committed Oct 12, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit bb19f7e38fa8caa65d843779569b46fc21fb6949
56 changes: 29 additions & 27 deletions packages/react-router-dom/index.tsx
Original file line number Diff line number Diff line change
@@ -207,7 +207,6 @@ export {
UNSAFE_NavigationContext,
UNSAFE_LocationContext,
UNSAFE_RouteContext,
UNSAFE_ViewTransitionContext,
UNSAFE_useRouteId,
} from "react-router";
//#endregion
@@ -348,6 +347,8 @@ if (__DEV__) {
ViewTransitionContext.displayName = "ViewTransition";
}

export { ViewTransitionContext as UNSAFE_ViewTransitionContext };

//#endregion

////////////////////////////////////////////////////////////////////////////////
@@ -1823,33 +1824,34 @@ function useViewTransitionState(
DataRouterHook.useViewTransitionState
);
let path = useResolvedPath(to, { relative: opts.relative });
if (vtContext.isTransitioning) {
let currentPath =
stripBasename(vtContext.currentLocation.pathname, basename) ||
vtContext.currentLocation.pathname;
let nextPath =
stripBasename(vtContext.nextLocation.pathname, basename) ||
vtContext.nextLocation.pathname;

// Transition is active if we're going to or coming from the indicated
// destination. This ensures that other PUSH navigations that reverse
// an indicated transition apply. I.e., on the list view you have:
//
// <NavLink to="/details/1" unstable_viewTransition>
//
// If you click the breadcrumb back to the list view:
//
// <NavLink to="/list" unstable_viewTransition>
//
// We should apply the transition because it's indicated as active going
// from /list -> /details/1 and therefore should be active on the reverse
// (even though this isn't strictly a POP reverse)
return (
matchPath(path.pathname, nextPath) != null ||
matchPath(path.pathname, currentPath) != null
);
if (!vtContext.isTransitioning) {
return false;
}
return false;

let currentPath =
stripBasename(vtContext.currentLocation.pathname, basename) ||
vtContext.currentLocation.pathname;
let nextPath =
stripBasename(vtContext.nextLocation.pathname, basename) ||
vtContext.nextLocation.pathname;

// Transition is active if we're going to or coming from the indicated
// destination. This ensures that other PUSH navigations that reverse
// an indicated transition apply. I.e., on the list view you have:
//
// <NavLink to="/details/1" unstable_viewTransition>
//
// If you click the breadcrumb back to the list view:
//
// <NavLink to="/list" unstable_viewTransition>
//
// We should apply the transition because it's indicated as active going
// from /list -> /details/1 and therefore should be active on the reverse
// (even though this isn't strictly a POP reverse)
return (
matchPath(path.pathname, nextPath) != null ||
matchPath(path.pathname, currentPath) != null
);
}

export { useViewTransitionState as unstable_useViewTransitionState };
21 changes: 12 additions & 9 deletions packages/react-router-dom/server.tsx
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ import {
Router,
UNSAFE_DataRouterContext as DataRouterContext,
UNSAFE_DataRouterStateContext as DataRouterStateContext,
UNSAFE_ViewTransitionContext as ViewTransitionContext,
} from "react-router-dom";

export interface StaticRouterProps {
@@ -131,15 +132,17 @@ export function StaticRouterProvider({
<>
<DataRouterContext.Provider value={dataRouterContext}>
<DataRouterStateContext.Provider value={state}>
<Router
basename={dataRouterContext.basename}
location={state.location}
navigationType={state.historyAction}
navigator={dataRouterContext.navigator}
static={dataRouterContext.static}
>
<DataRoutes routes={router.routes} state={state} />
</Router>
<ViewTransitionContext.Provider value={{ isTransitioning: false }}>
<Router
basename={dataRouterContext.basename}
location={state.location}
navigationType={state.historyAction}
navigator={dataRouterContext.navigator}
static={dataRouterContext.static}
>
<DataRoutes routes={router.routes} state={state} />
</Router>
</ViewTransitionContext.Provider>
</DataRouterStateContext.Provider>
</DataRouterContext.Provider>
{hydrateScript ? (