-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(replay): Add non-async flush for page unloads #6854
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
Conversation
Add a method of using a non-async flush so that we are able to send a segment when the user unloads the page.
69d7dec
to
ba73d92
Compare
size-limit report 📦
|
@mydea After some testing, it looks like it's gets to the request part, but gets cancelled and the envelope does not end up getting sent. |
packages/replay/src/eventBuffer.ts
Outdated
}); | ||
} | ||
|
||
public finishImmediate(): string { |
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.
After thinking about this, let's go with finishSync
here maybe? That's maybe a bit clearer in what it does?
Also I we can save a few bytes by having finishSync
be the actual implementation (instead of _finish
) and using this in finish()
.
packages/replay/src/replay.ts
Outdated
@@ -625,7 +625,7 @@ export class ReplayContainer implements ReplayContainerInterface { | |||
// Send replay when the page/tab becomes hidden. There is no reason to send | |||
// replay if it becomes visible, since no actions we care about were done | |||
// while it was hidden | |||
this._conditionalFlush(); | |||
this._conditionalFlush({ finishImmediate: true }); |
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.
option could be sync: true
, slightly shorter?
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.
Also because the immediate
naming clashes a bit with finishImmediate
, which is not actually sync, so IMHO using different naming here would make sense!
packages/replay/src/replay.ts
Outdated
* synchronously retrieve pending events from buffer and send request asap. | ||
*/ | ||
if (options.finishImmediate) { | ||
void this._runFlush(options); |
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.
I think we need to use a fully sync code path here - as this is an async function, it may only be run in the next tick, which may be the problem. I'll try to see if I can try it locally...!
I made a PR to this branch here: #6859 |
In order to clean up our list of open PRs, I'm going to close this because of #6698 being closed:
@billyvg feel free to reopen this anytime :) |
Add a method of using a non-async flush so that we are able to send a segment when the user unloads the page. This means the segment for blurs/unloads will be uncompressed if default settings are used.
Closes #6698 as we can avoid constant writes to sessionStorage and having to maintain additional state.