-
Notifications
You must be signed in to change notification settings - Fork 443
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
feat: add sendBeacon request parameters hook #555
Conversation
This change introduces a new hook called `resolveSendBeaconRequestParameters`. This enables consumers to modify a subset of the RequestInit parameters being used by the fetch request that polyfills the navigator.sendBeacon API in the worker context, e.g. setting keepalive: false
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Thank you @hoebbelsB |
I just went on vacation after opening the pr. Will update with tests when I'm back :) |
Thanks for your help, have a nice vacation 🏝️ |
hey @gioboa just added the tests, please check if this is sufficient :) |
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.
@hoebbelsB the core team verified it, that's a great piece of code.
Thanks for your help.
Amazing work, thanks so much for this PR! |
What is it?
Description
This change introduces a new hook called
resolveSendBeaconRequestParameters
on thePartytownConfig
. This enables consumers to modify a subset of theRequestInit
parameters being used by the fetch request that polyfills the navigator.sendBeacon API in the worker context, e.g. setting keepalive: false.Alternative solution
An alternative solution would be to just set
keepalive: false
as default. But as I am not aware of the reasoning behind your defaults, I thought it's a good idea to make it user configurable.Use cases and why
The current implementation of the
sendBeacon
has static values for theRequestInit
parameters it uses to initialize the post request. The goal is to make those parameters being user configurable.I am not 100% sure why you have chosen to go with those default values, but I've notice that espcially
keepalive: true
is causing troubles in combination with google analytics (analytics.js).I've already pointed out the behavior it causes in this issue #492, but at that point I didn't know the root cause is
keepalive: true
.Short description of what happens with some visuals.
The application starts behaving normal, the first couple of requests sent via
sendBeacon
are actually fine and not producing any errors. Until a certain amount of events was sent, most of the following requests are simply inpending
state forever.The "failing" requests are also producing errors like crazy
Lastly, I've figured out that also the "good" requests are having issues, as they seem to actually never finish until they run into some timeout.
After manually setting
keepalive: false
and override the script locally, the application suddenly recovers and all consequent requests are perfectly fine. It looks like the never finishing requests are filling some queue which causes consequent requests to be stalled.Checklist: