-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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(remix): Capture thrown fetch responses. #10166
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
packages/remix/test/integration/app_v1/routes/loader-throw-response/$id.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from '../../../common/routes/loader-throw-response.$id'; | ||
export { default } from '../../../common/routes/loader-throw-response.$id'; |
2 changes: 2 additions & 0 deletions
2
packages/remix/test/integration/app_v2/routes/loader-throw-response.$id.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from '../../common/routes/loader-throw-response.$id'; | ||
export { default } from '../../common/routes/loader-throw-response.$id'; |
24 changes: 24 additions & 0 deletions
24
packages/remix/test/integration/common/routes/loader-throw-response.$id.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { LoaderFunction } from '@remix-run/node'; | ||
import { useLoaderData } from '@remix-run/react'; | ||
|
||
export const loader: LoaderFunction = async ({ params: { id } }) => { | ||
if (id === '-1') { | ||
throw new Response(null, { | ||
status: 500, | ||
statusText: 'Not found', | ||
}); | ||
} | ||
|
||
return { message: 'hello world' }; | ||
}; | ||
|
||
export default function LoaderThrowResponse() { | ||
const data = useLoaderData(); | ||
|
||
return ( | ||
<div> | ||
<h1>Loader Throw Response</h1> | ||
<span>{data ? data.message : 'No Data'} </span> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The standard fetch API should always work (with remix polyfill, with any other polyfill, or no polyfill but node v18+), so I think the code can be cleaner if
getInternalSymbols
and the associated code logic is deleted.Thoughts?
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.
We had issues with extracting
headers
in previous Remix versions, and we need to stay backwards compatible. For reference: #6139 (comment)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.
@onurtemizkan thanks for the reference. Yes - Remix uses a Proxy but as long as the code sticks to the Standard API interface, it shouldn't cause problems.
I understand that the issues happened before this layer was added, per your commit at 0ee35f0. I do not know the whole code, but from what I see in this layer,
request.headers
is only used in this function, and the usage seems consistent with the standard API. I wouldn't expect it to introduce any problems if the code is changed to use the standard API in thisnormalizeRemixRequest
function. Is this wrong?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.
The problem is that we had been reading
req.headers
directly before 0ee35f0. We still provide official support to theremix
version andweb-fetch
version (as it's dependency) that caused #6139.We don't rely on those versions being aligned to the current Standard API Interface (which was the reason we ended up vendoring code from them). So, IMO it's not worth risking to revive old resolved issues if this patch resolves the non-polyfilled usage. If we decide in the future to drop support for Remix v1 or Node versions < 18 in the Remix SDK, we can work on a broader cleanup, deleting vendored code (which we generally use as the last resort).
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.
Yes - what I mean is that while I do not know the code usage before 0ee35f0, I can see how the
normalizeRemixRequest
function added in 0ee35f0 commit is reading the headers. I do not think changing this function to read from the Standard API should create any problems or break backward compatibility.If they are polyfilling the standard Fetch interface and are not aligned with it, then that's kinda their issue and they should fix that...
Hopefully, this is guaranteed by a test 😅.
All good to leave that cleanup for later!