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

fix: allow undefined to be resolved with <Await> #11513

Merged
merged 1 commit into from
Apr 29, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/heavy-lies-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-router": patch
---

allow undefined to be resolved with `<Await>`
29 changes: 29 additions & 0 deletions packages/react-router/__tests__/data-memory-router-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3089,6 +3089,35 @@ describe("createMemoryRouter", () => {
`);
});

it("can render raw resolved to undefined promises with <Await>", async () => {
let dfd = createDeferred();

let { container } = render(
<React.Suspense fallback={<p>Loading...</p>}>
<Await resolve={dfd.promise}>{(data) => <p>{String(data)}</p>}</Await>
</React.Suspense>
);

console.log(getHtml(container));
expect(getHtml(container)).toMatchInlineSnapshot(`
"<div>
<p>
Loading...
</p>
</div>"
`);

dfd.resolve(undefined);
await waitFor(() => screen.getByText("undefined"));
expect(getHtml(container)).toMatchInlineSnapshot(`
"<div>
<p>
undefined
</p>
</div>"
`);
});

it("can render raw resolved promises with <Await>", async () => {
let dfd = createDeferred();

Expand Down
4 changes: 2 additions & 2 deletions packages/react-router/lib/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,9 @@ class AwaitErrorBoundary extends React.Component<
// Already tracked promise - check contents
promise = resolve;
status =
promise._error !== undefined
"_error" in promise
? AwaitRenderStatus.error
: promise._data !== undefined
: "_data" in promise
? AwaitRenderStatus.success
: AwaitRenderStatus.pending;
} else {
Expand Down