Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/hot-insects-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/router": patch
---

Preserve view transition through redirects
36 changes: 36 additions & 0 deletions packages/router/__tests__/view-transition-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IDLE_NAVIGATION } from "../router";
import { cleanup, setup } from "./utils/data-router-setup";
import { createFormData } from "./utils/utils";

describe("view transitions", () => {
// Detect any failures inside the router navigate code
Expand Down Expand Up @@ -136,4 +137,39 @@ describe("view transitions", () => {
unsubscribe();
t.router.dispose();
});

it("preserves pending view transitions through redirects", async () => {
let t = setup({
routes: [
{ path: "/" },
{ id: "a", path: "/a", action: true },
{ path: "/b" },
],
});
let spy = jest.fn();
let unsubscribe = t.router.subscribe(spy);

let A = await t.navigate("/a", {
formMethod: "post",
formData: createFormData({}),
unstable_viewTransition: true,
});

await A.actions.a.redirect("/b");
expect(spy).toHaveBeenLastCalledWith(
expect.objectContaining({
navigation: IDLE_NAVIGATION,
location: expect.objectContaining({ pathname: "/b" }),
}),
expect.objectContaining({
unstable_viewTransitionOpts: {
currentLocation: expect.objectContaining({ pathname: "/" }),
nextLocation: expect.objectContaining({ pathname: "/b" }),
},
})
);

unsubscribe();
t.router.dispose();
});
});
25 changes: 18 additions & 7 deletions packages/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1779,7 +1779,7 @@ export function createRouter(init: RouterInit): Router {
);
replace = location === state.location.pathname + state.location.search;
}
await startRedirectNavigation(request, result, {
await startRedirectNavigation(request, result, true, {
submission,
replace,
});
Expand Down Expand Up @@ -2032,7 +2032,7 @@ export function createRouter(init: RouterInit): Router {
revalidatingFetchers[redirect.idx - matchesToLoad.length].key;
fetchRedirectIds.add(fetcherKey);
}
await startRedirectNavigation(request, redirect.result, {
await startRedirectNavigation(request, redirect.result, true, {
replace,
});
return { shortCircuited: true };
Expand Down Expand Up @@ -2328,7 +2328,7 @@ export function createRouter(init: RouterInit): Router {
} else {
fetchRedirectIds.add(key);
updateFetcherState(key, getLoadingFetcher(submission));
return startRedirectNavigation(fetchRequest, actionResult, {
return startRedirectNavigation(fetchRequest, actionResult, false, {
fetcherSubmission: submission,
});
}
Expand Down Expand Up @@ -2449,7 +2449,11 @@ export function createRouter(init: RouterInit): Router {
revalidatingFetchers[redirect.idx - matchesToLoad.length].key;
fetchRedirectIds.add(fetcherKey);
}
return startRedirectNavigation(revalidationRequest, redirect.result);
return startRedirectNavigation(
revalidationRequest,
redirect.result,
false
);
}

// Process and commit output from loaders
Expand Down Expand Up @@ -2610,7 +2614,7 @@ export function createRouter(init: RouterInit): Router {
return;
} else {
fetchRedirectIds.add(key);
await startRedirectNavigation(fetchRequest, result);
await startRedirectNavigation(fetchRequest, result, false);
return;
}
}
Expand Down Expand Up @@ -2649,6 +2653,7 @@ export function createRouter(init: RouterInit): Router {
async function startRedirectNavigation(
request: Request,
redirect: RedirectResult,
isNavigation: boolean,
{
submission,
fetcherSubmission,
Expand Down Expand Up @@ -2735,8 +2740,11 @@ export function createRouter(init: RouterInit): Router {
...activeSubmission,
formAction: location,
},
// Preserve this flag across redirects
// Preserve these flags across redirects
preventScrollReset: pendingPreventScrollReset,
enableViewTransition: isNavigation
? pendingViewTransitionEnabled
: undefined,
});
} else {
// If we have a navigation submission, we will preserve it through the
Expand All @@ -2749,8 +2757,11 @@ export function createRouter(init: RouterInit): Router {
overrideNavigation,
// Send fetcher submissions through for shouldRevalidate
fetcherSubmission,
// Preserve this flag across redirects
// Preserve these flags across redirects
preventScrollReset: pendingPreventScrollReset,
enableViewTransition: isNavigation
? pendingViewTransitionEnabled
: undefined,
});
}
}
Expand Down