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(setupWorker): resolve the "start" promise after the worker has activated #1146

Merged
merged 1 commit into from Mar 6, 2022

Conversation

kettanaito
Copy link
Member

@kettanaito kettanaito commented Mar 6, 2022

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 6, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit fd3ab7d:

Sandbox Source
MSW React Configuration

@kettanaito kettanaito merged commit f6e709c into main Mar 6, 2022
@kettanaito kettanaito deleted the feat/worker-await-activated branch March 6, 2022 23:48
// (i.e. when reloading the page after a successful activation).
if (pendingInstance) {
await new Promise<void>((resolve) => {
pendingInstance.addEventListener('statechange', () => {
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

both registration.installing.addEventListener and registration.waiting.addEventListener can listen to the same event 'statechange'?

Copy link
Member Author

Choose a reason for hiding this comment

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

@Aprillion yes. Those properties return a worker instance in a different state. But it's the same worker instance as the activated worker, having the same event listeners. This is how you know if a state transitions into another state.

@github-actions
Copy link

github-actions bot commented Mar 7, 2022

🎉 This PR is included in version 0.39.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"setupWorker" Promise may resolve before the worker is activated
2 participants