Skip to content

Remove defer implementation in favor of raw promises #11744

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 4 commits into from
Jul 1, 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: 12 additions & 0 deletions .changeset/chilled-masks-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"react-router-dom": major
"react-router": major
---

Remove the original `defer` implementation in favor of using raw promises via single fetch and `turbo-stream`. This removes these exports from React Router:

- `defer`
- `AbortedDeferredError`
- `type TypedDeferredData`
- `UNSAFE_DeferredData`
- `UNSAFE_DEFERRED_SYMBOL`,
6 changes: 3 additions & 3 deletions integration/client-data-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,13 @@ test.describe("Client Data", () => {
}),
"app/routes/parent.child.tsx": js`
import * as React from 'react';
import { defer, json } from "react-router"
import { json } from "react-router"
import { Await, useLoaderData } from "react-router"
export function loader() {
return defer({
return {
message: 'Child Server Loader',
lazy: new Promise(r => setTimeout(() => r("Child Deferred Data"), 1000)),
});
};
}
export async function clientLoader({ serverLoader }) {
let data = await serverLoader();
Expand Down
12 changes: 6 additions & 6 deletions integration/defer-loader-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ test.describe("deferred loaders", () => {
`,

"app/routes/redirect.tsx": js`
import { defer } from "react-router";
export function loader() {
return defer({food: "pizza"}, { status: 301, headers: { Location: "/?redirected" } });
export function loader({ response }) {
response.status = 301;
response.headers.set("Location", "/?redirected");
return { food: "pizza" };
}
export default function Redirect() {return null;}
`,

"app/routes/direct-promise-access.tsx": js`
import * as React from "react";
import { defer } from "react-router";
import { useLoaderData, Link, Await } from "react-router";
export function loader() {
return defer({
return {
bar: new Promise(async (resolve, reject) => {
resolve("hamburger");
}),
});
};
}
let count = 0;
export default function Index() {
Expand Down
Loading