Skip to content

Commit

Permalink
fix: allow undefined to be resolved with <Await> (#11513)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-ebey committed Apr 29, 2024
1 parent 56969f2 commit e0b1db4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-lies-ring.md
@@ -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
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
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

0 comments on commit e0b1db4

Please sign in to comment.