Skip to content

Stabilize viewTransition and flushSync APIs #11990

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

Merged
merged 1 commit into from
Sep 12, 2024
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
12 changes: 6 additions & 6 deletions packages/react-router/__tests__/data-router-no-dom-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe("RouterProvider works when no DOM APIs are available", () => {

await renderer.act(async () => {
router.navigate("/foo", {
unstable_viewTransition: true,
viewTransition: true,
});
await new Promise((resolve) => setTimeout(resolve, 0));
});
Expand All @@ -100,11 +100,11 @@ describe("RouterProvider works when no DOM APIs are available", () => {
expect(spy.mock.calls[0][0].location.pathname).toBe("/");
expect(spy.mock.calls[0][0].navigation.state).toBe("loading");
expect(spy.mock.calls[0][0].navigation.location.pathname).toBe("/foo");
expect(spy.mock.calls[0][1].unstable_viewTransitionOpts).toBeUndefined();
expect(spy.mock.calls[0][1].viewTransitionOpts).toBeUndefined();

expect(spy.mock.calls[1][0].location.pathname).toBe("/foo");
expect(spy.mock.calls[1][0].navigation.state).toBe("idle");
expect(spy.mock.calls[1][1].unstable_viewTransitionOpts).toEqual({
expect(spy.mock.calls[1][1].viewTransitionOpts).toEqual({
currentLocation: {
hash: "",
key: "default",
Expand Down Expand Up @@ -157,7 +157,7 @@ describe("RouterProvider works when no DOM APIs are available", () => {

await renderer.act(async () => {
router.navigate("/foo", {
unstable_flushSync: true,
flushSync: true,
});
await new Promise((resolve) => setTimeout(resolve, 0));
});
Expand All @@ -172,11 +172,11 @@ describe("RouterProvider works when no DOM APIs are available", () => {
expect(spy.mock.calls[0][0].location.pathname).toBe("/");
expect(spy.mock.calls[0][0].navigation.state).toBe("loading");
expect(spy.mock.calls[0][0].navigation.location.pathname).toBe("/foo");
expect(spy.mock.calls[0][1].unstable_flushSync).toBe(true);
expect(spy.mock.calls[0][1].flushSync).toBe(true);

expect(spy.mock.calls[1][0].location.pathname).toBe("/foo");
expect(spy.mock.calls[1][0].navigation.state).toBe("idle");
expect(spy.mock.calls[1][1].unstable_flushSync).toBe(false);
expect(spy.mock.calls[1][1].flushSync).toBe(false);

unsubscribe();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7380,13 +7380,13 @@ function testDomRouter(
return (
<div>
<Link to="/a">/a</Link>
<Link to="/b" unstable_viewTransition>
<Link to="/b" viewTransition>
/b
</Link>
<Form action="/c">
<button type="submit">/c</button>
</Form>
<Form action="/d" unstable_viewTransition>
<Form action="/d" viewTransition>
<button type="submit">/d</button>
</Form>
<Outlet />
Expand Down Expand Up @@ -7461,7 +7461,7 @@ function testDomRouter(
Component() {
return (
<>
<Link to="/page" unstable_viewTransition>
<Link to="/page" viewTransition>
/page
</Link>
<Outlet />
Expand Down
40 changes: 20 additions & 20 deletions packages/react-router/__tests__/dom/flush-sync-navigations-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("flushSync", () => {
<>
<h1>About</h1>
<button
onClick={() => navigate("/", { unstable_flushSync: true })}
onClick={() => navigate("/", { flushSync: true })}
>
Go to /
</button>
Expand All @@ -60,14 +60,14 @@ describe("flushSync", () => {
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenLastCalledWith(
expect.anything(),
expect.objectContaining({ unstable_flushSync: false })
expect.objectContaining({ flushSync: false })
);

fireEvent.click(screen.getByText("Go to /"));
await waitFor(() => screen.getByText("Home"));
expect(spy).toHaveBeenLastCalledWith(
expect.anything(),
expect.objectContaining({ unstable_flushSync: true })
expect.objectContaining({ flushSync: true })
);

expect(spy).toHaveBeenCalledTimes(2);
Expand Down Expand Up @@ -109,7 +109,7 @@ describe("flushSync", () => {
onClick={() =>
submit(
{},
{ method: "post", action: "/", unstable_flushSync: true }
{ method: "post", action: "/", flushSync: true }
)
}
>
Expand All @@ -135,14 +135,14 @@ describe("flushSync", () => {
fireEvent.click(screen.getByText("Go to /about"));
await waitFor(() => screen.getByText("About"));
expect(spy).toHaveBeenCalledTimes(2);
expect(spy.mock.calls[0][1].unstable_flushSync).toBe(false);
expect(spy.mock.calls[1][1].unstable_flushSync).toBe(false);
expect(spy.mock.calls[0][1].flushSync).toBe(false);
expect(spy.mock.calls[1][1].flushSync).toBe(false);

fireEvent.click(screen.getByText("Go to /"));
await waitFor(() => screen.getByText("Home"));
expect(spy).toHaveBeenCalledTimes(4);
expect(spy.mock.calls[2][1].unstable_flushSync).toBe(true);
expect(spy.mock.calls[3][1].unstable_flushSync).toBe(false);
expect(spy.mock.calls[2][1].flushSync).toBe(true);
expect(spy.mock.calls[3][1].flushSync).toBe(false);

router.dispose();
});
Expand All @@ -164,7 +164,7 @@ describe("flushSync", () => {
<pre>{`async:${fetcher1.data}:${fetcher1.state}`}</pre>
<button
onClick={() =>
fetcher2.load("/fetch", { unstable_flushSync: true })
fetcher2.load("/fetch", { flushSync: true })
}
>
Load sync
Expand Down Expand Up @@ -197,14 +197,14 @@ describe("flushSync", () => {
fireEvent.click(screen.getByText("Load async"));
await waitFor(() => screen.getByText("async:LOADER:idle"));
expect(spy).toHaveBeenCalledTimes(2);
expect(spy.mock.calls[0][1].unstable_flushSync).toBe(false);
expect(spy.mock.calls[1][1].unstable_flushSync).toBe(false);
expect(spy.mock.calls[0][1].flushSync).toBe(false);
expect(spy.mock.calls[1][1].flushSync).toBe(false);

fireEvent.click(screen.getByText("Load sync"));
await waitFor(() => screen.getByText("sync:LOADER:idle"));
expect(spy).toHaveBeenCalledTimes(4);
expect(spy.mock.calls[2][1].unstable_flushSync).toBe(true);
expect(spy.mock.calls[3][1].unstable_flushSync).toBe(false);
expect(spy.mock.calls[2][1].flushSync).toBe(true);
expect(spy.mock.calls[3][1].flushSync).toBe(false);

router.dispose();
});
Expand Down Expand Up @@ -233,7 +233,7 @@ describe("flushSync", () => {
onClick={() =>
fetcher2.submit(
{},
{ method: "post", action: "/", unstable_flushSync: true }
{ method: "post", action: "/", flushSync: true }
)
}
>
Expand All @@ -260,16 +260,16 @@ describe("flushSync", () => {
fireEvent.click(screen.getByText("Submit async"));
await waitFor(() => screen.getByText("async:ACTION:idle"));
expect(spy).toHaveBeenCalledTimes(3);
expect(spy.mock.calls[0][1].unstable_flushSync).toBe(false);
expect(spy.mock.calls[1][1].unstable_flushSync).toBe(false);
expect(spy.mock.calls[2][1].unstable_flushSync).toBe(false);
expect(spy.mock.calls[0][1].flushSync).toBe(false);
expect(spy.mock.calls[1][1].flushSync).toBe(false);
expect(spy.mock.calls[2][1].flushSync).toBe(false);

fireEvent.click(screen.getByText("Submit sync"));
await waitFor(() => screen.getByText("sync:ACTION:idle"));
expect(spy).toHaveBeenCalledTimes(6);
expect(spy.mock.calls[3][1].unstable_flushSync).toBe(true);
expect(spy.mock.calls[4][1].unstable_flushSync).toBe(false);
expect(spy.mock.calls[5][1].unstable_flushSync).toBe(false);
expect(spy.mock.calls[3][1].flushSync).toBe(true);
expect(spy.mock.calls[4][1].flushSync).toBe(false);
expect(spy.mock.calls[5][1].flushSync).toBe(false);

router.dispose();
});
Expand Down
38 changes: 19 additions & 19 deletions packages/react-router/__tests__/router/flush-sync-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ describe("flushSync", () => {
let A = await t.navigate("/a");
expect(spy).toHaveBeenLastCalledWith(
expect.anything(),
expect.objectContaining({ unstable_flushSync: false })
expect.objectContaining({ flushSync: false })
);
await A.loaders.a.resolve("A");
expect(spy).toHaveBeenLastCalledWith(
expect.anything(),
expect.objectContaining({ unstable_flushSync: false })
expect.objectContaining({ flushSync: false })
);

let B = await t.navigate("/b", { unstable_flushSync: true });
let B = await t.navigate("/b", { flushSync: true });
expect(spy).toHaveBeenLastCalledWith(
expect.anything(),
expect.objectContaining({ unstable_flushSync: true })
expect.objectContaining({ flushSync: true })
);
await B.loaders.b.resolve("B");
expect(spy).toHaveBeenLastCalledWith(
expect.anything(),
expect.objectContaining({ unstable_flushSync: false })
expect.objectContaining({ flushSync: false })
);

unsubscribe();
Expand All @@ -59,27 +59,27 @@ describe("flushSync", () => {
});
expect(spy).toHaveBeenLastCalledWith(
expect.anything(),
expect.objectContaining({ unstable_flushSync: false })
expect.objectContaining({ flushSync: false })
);
await A.actions.a.resolve("A");
expect(spy).toHaveBeenLastCalledWith(
expect.anything(),
expect.objectContaining({ unstable_flushSync: false })
expect.objectContaining({ flushSync: false })
);

let B = await t.navigate("/b", {
formMethod: "post",
formData: createFormData({}),
unstable_flushSync: true,
flushSync: true,
});
expect(spy).toHaveBeenLastCalledWith(
expect.anything(),
expect.objectContaining({ unstable_flushSync: true })
expect.objectContaining({ flushSync: true })
);
await B.actions.b.resolve("B");
expect(spy).toHaveBeenLastCalledWith(
expect.anything(),
expect.objectContaining({ unstable_flushSync: false })
expect.objectContaining({ flushSync: false })
);

unsubscribe();
Expand All @@ -97,25 +97,25 @@ describe("flushSync", () => {
let A = await t.fetch("/", key);
expect(spy).toHaveBeenLastCalledWith(
expect.anything(),
expect.objectContaining({ unstable_flushSync: false })
expect.objectContaining({ flushSync: false })
);
expect(t.fetchers[key].state).toBe("loading");

await A.loaders.root.resolve("ROOT");
expect(t.fetchers[key].data).toBe("ROOT");

let B = await t.fetch("/", key, { unstable_flushSync: true });
let B = await t.fetch("/", key, { flushSync: true });
expect(spy).toHaveBeenLastCalledWith(
expect.anything(),
expect.objectContaining({ unstable_flushSync: true })
expect.objectContaining({ flushSync: true })
);
expect(t.fetchers[key].state).toBe("loading");

await B.loaders.root.resolve("ROOT2");
expect(t.fetchers[key].data).toBe("ROOT2");
expect(spy).toHaveBeenLastCalledWith(
expect.anything(),
expect.objectContaining({ unstable_flushSync: false })
expect.objectContaining({ flushSync: false })
);

unsubscribe();
Expand All @@ -136,33 +136,33 @@ describe("flushSync", () => {
});
expect(spy).toHaveBeenLastCalledWith(
expect.anything(),
expect.objectContaining({ unstable_flushSync: false })
expect.objectContaining({ flushSync: false })
);
expect(t.fetchers[key].state).toBe("submitting");

await A.actions.root.resolve("ROOT");
expect(spy).toHaveBeenLastCalledWith(
expect.anything(),
expect.objectContaining({ unstable_flushSync: false })
expect.objectContaining({ flushSync: false })
);
expect(t.fetchers[key].data).toBe("ROOT");

let B = await t.fetch("/", key, {
formMethod: "post",
formData: createFormData({}),
unstable_flushSync: true,
flushSync: true,
});
expect(spy).toHaveBeenLastCalledWith(
expect.anything(),
expect.objectContaining({ unstable_flushSync: true })
expect.objectContaining({ flushSync: true })
);
expect(t.fetchers[key].state).toBe("submitting");

await B.actions.root.resolve("ROOT2");
expect(t.fetchers[key].data).toBe("ROOT2");
expect(spy).toHaveBeenLastCalledWith(
expect.anything(),
expect.objectContaining({ unstable_flushSync: false })
expect.objectContaining({ flushSync: false })
);

unsubscribe();
Expand Down
Loading