fix: use wrapper to allow patching global fetch#377
Conversation
|
nuxt/test-utils#775 just mentioning this one here, thanks for taking this up! |
fetch
|
Thanks for PR. I was thinking of same solution too. I agree it is needed but (sadly) means 1) we allow patching behavior of a standard primitive 2) adds small call overhead. @dwightjack Have you tried this solution btw? I guess we might need to patch the node entrypoint as well. (also in |
Oh, I missed that part. I updated the PR (4026829). I wasn't able to make a full reproduction of Nuxt + MSW on StackBlitz (I guess there are some problems with service workers), so I pushed it to a GitHub repository: https://github.com/dwightjack/ofetch-msw-reproduction Some notes:
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #377 +/- ##
===========================================
+ Coverage 56.86% 67.08% +10.22%
===========================================
Files 16 16
Lines 728 474 -254
Branches 113 116 +3
===========================================
- Hits 414 318 -96
+ Misses 303 146 -157
+ Partials 11 10 -1 ☔ View full report in Codecov by Sentry. |
|
I'm working to add some CF Pages support to I think the work being done here would unblock this use-case too! |
|
Related nuxt/nuxt#24519 |
Test for pageload. Tests for distributed tracing for navigations are still coming (waiting for next Nuxt version which includes the new version of ofetch with [this PR](unjs/ofetch#377))
🔗 Linked issue
#295
❓ Type of change
📚 Description
I was investigating the usage of MSW on Nuxt 3 and encountered #295. Looking at the source code, I think that a possible solution is to define the local
fetchconstant as getter instead of a reference toglobalThils.fetch. In this way, 3rd party library can patch and overwrite the global object without us referencing an outdated function:At the moment, I cannot think of possible breaking changes or side effects caused by this change, but I might miss something.
📝 Checklist