-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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: invalid deferred data hanging response #6793
Conversation
🦋 Changeset detectedLatest commit: 4c2cfaa The changes in this PR will be included in the next version bump. This PR includes changesets to release 18 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Thank you sir! |
packages/remix-react/components.tsx
Outdated
if (typeof data === "undefined") { | ||
console.error( | ||
`Deferred data for ${routeId} ${key} resolved to undefined, defaulting to null.` | ||
); | ||
data = null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could make this a TS error?
export function loader() {
return defer({
something: undefined, // ❌
lazy: Promise.resolve(undefined), // ❌
else: null, // ✅
lazy2: Promise.resolve(null), // ✅
});
}
I didn't dig too deep but it looks like we have:
export type DeferFunction = <Data extends Record<string, unknown>>(
data: Data,
init?: number | ResponseInit
) => TypedDeferredData<Data>;
I wonder if we could enhance that Record
to allow something like NonNullable<unknown> | null | Promise<NonNullable<unknown> | null>
as a value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm honestly not sure how unknown would behave in this situation. @pcattori, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC I got the NonNullable<unknown> | null
trick from Pedro for use in RR a while back: https://github.com/remix-run/react-router/blob/main/packages/router/utils.ts#L160
I believe NonNullable<unknown>
allows anything except undefined
/null
and then you can add null
back in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do that in a followup PR if we want to.
Co-authored-by: Matt Brophy <matt@brophy.org>
Just clarifying - this should result in the warning and a resolution of export function loader() {
return defer({ data: Promise.resolve(undefined) });
} It hangs for ~5 seconds then prints this in the console but does correctly resolve my
I wasn't sure if this was supposed to still hit the timeout or it it should have flipped over and rendered However, if I introduce a delay I still get a Server timeout error boundary rendered - should that be defaulting over to export function loader() {
return defer({
data: new Promise((r) => setTimeout(() => r(undefined), 1000)),
});
} |
That should flip over immediately. I'll see if I can get a test in for that. |
Alternate approach in remix-run/react-router#10690 - we'd still want to keep some of the improved error handling from here if we go with that. |
Dependent on remix-run/react-router#10690 |
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
Closes: #
Testing Strategy: