-
-
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
Conversation
1bb2b1c
to
0f29581
Compare
if (!requestInternalsSymbol && !request.headers) { | ||
throw new Error('Could not find request headers'); | ||
} | ||
|
||
const { parsedURL } = request[requestInternalsSymbol]; | ||
const headers = new Headers(request[requestInternalsSymbol].headers); | ||
const parsedURL = requestInternalsSymbol ? request[requestInternalsSymbol].parsedURL : new URL(request.url); | ||
const headers = requestInternalsSymbol ? new Headers(request[requestInternalsSymbol].headers) : request.headers; |
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 this normalizeRemixRequest
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 the remix
version and web-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.
The problem is that we had been reading req.headers directly before 0ee35f0.
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.
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)
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...
So, IMO it's not worth risking to revive old resolved issues if this patch resolves the non-polyfilled usage.
Hopefully, this is guaranteed by a test 😅.
All good to leave that cleanup for later!
One missing bit down below: There's no "nice" and standard way to know the size via the standard fetch API without reading the body itself. This is a little unreliable because the body can only be consumed once, and userland may have already read it (so this information wouldn't be available). In case they did not, you still don't want to do it (because they might have code that reads it after Sentry). You can try to clone the I recommend simply deleting the logic, but if you want to rework it, in a future-proof and backward-compatible way:
Another alternative for when |
Yes, this access needs to be safeguarded. Thanks for pointing it out. I'll update the PR. If the |
a922ec0
to
f15ebc9
Compare
Fixes: #10160
Potentially fixes: #10002
This PR adds support for extracting
header
data from thrown non-Remix responses (fetch responses) inside loaders / actions.