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: pass original fetch args along #1351

Merged
merged 2 commits into from
Aug 19, 2024
Merged

Conversation

pauldambra
Copy link
Member

@pauldambra pauldambra commented Aug 10, 2024

When wrapping fetch we take a url, init pair and create a request object

When we pass on and call the original fetch method we pass the request object. this is technically equivalent to the original but not literally equivalent which can cause problems if there are further wrappers on fetch

see: #1326

We actively don't want to alter the fetch details so it should be 100% safe to use the original args when calling the original fetch 🤷

Copy link

vercel bot commented Aug 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
posthog-js ✅ Ready (Inspect) Visit Preview Aug 19, 2024 0:19am

Copy link

github-actions bot commented Aug 10, 2024

Size Change: +6 B (0%)

Total Size: 1.17 MB

Filename Size Change
dist/array.full.js 333 kB +2 B (0%)
dist/recorder-v2.js 110 kB +2 B (0%)
dist/recorder.js 110 kB +2 B (0%)
ℹ️ View Unchanged
Filename Size
dist/array.js 154 kB
dist/exception-autocapture.js 10.4 kB
dist/main.js 155 kB
dist/module.js 154 kB
dist/surveys-preview.js 59.8 kB
dist/surveys.js 66 kB
dist/tracing-headers.js 8.26 kB
dist/web-vitals.js 5.79 kB

compressed-size-action

@daibhin daibhin added the bump minor Bump minor version when this PR gets merged label Aug 12, 2024
Copy link
Contributor

@daibhin daibhin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change makes sense. I think we should be returning exactly the arguments we were given. Probably an oversight earlier on to have returned the constructed Request so worth fixing forward.

There's a risk we break this the other way e.g. customers have come to rely on the output of our fetch returning a Request object. We won't really know that without shipping.

My suggestion would be to get this out there as a minor bump. At least then people are more likely to be able to track the version bump if it does cause an issue for them. Secondly, there's always the escape hatch of staying on the previous version until they've had a chance to fix their reliant code (which should be trivial either way).

The only other alternative I can think of is passing res = await originalFetch(req, init) back but that feels less good. We'd be preserving current functionality at the expense of correctness. Given the points above it's probably just worth fixing everything now and dealing with any consequential issues that arise.

@pauldambra pauldambra marked this pull request as ready for review August 19, 2024 12:00
@pauldambra pauldambra added bump patch Bump patch version when this PR gets merged bump minor Bump minor version when this PR gets merged and removed bump minor Bump minor version when this PR gets merged bump patch Bump patch version when this PR gets merged labels Aug 19, 2024
@pauldambra pauldambra changed the title fix: pass original along fix: pass original fetch args along Aug 19, 2024
@pauldambra pauldambra merged commit e2da050 into main Aug 19, 2024
14 checks passed
@pauldambra pauldambra deleted the fix/pass-original-along branch August 19, 2024 13:44
@weilandia
Copy link

weilandia commented Aug 20, 2024

Our app went down tonight because of an issue with Posthog overwriting fetch in this file. Not sure that this exact change is the culprit, but the changes made to window.fetch in recorder.ts made RTKQuery unusable and left us with a very confusing FE bug that came down to the Posthog assets loading and breaking fetch. We solved it in the interim by using cross-fetch as the fetch function in RTK.

https://us-assets.i.posthog.com/src/entrypoints/recorder.ts

@pauldambra
Copy link
Member Author

oh yuck! so sorry @weilandia! will revert this change I've seen a few reports of similar and I'd be amazed if it was any of the other changes yesterday

@weilandia
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump minor Bump minor version when this PR gets merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants