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 race condition during initialization #62

Merged
merged 1 commit into from
May 20, 2021

Conversation

guillaumejenkins
Copy link
Collaborator

The current init logic first checks whether document.readyState === 'complete' before calling init(), otherwise it starts listening for the DOMContentLoaded event and sets init() as the event callback.

According to the DOMContentLoaded documentation, it can fire while document.readyState is still 'interactive'. So, the current logic has a race condition where if the DOMContentLoaded event has already fired before we can start listening to it, and the document.readyState isn't 'complete' yet, then init() will never be called. This was preventing the polyfill from working for the demo page (and other simple pages on the web like www.example.com) in some cases, such as in the FireFox browser.

The fix is to listen to the readystatechange event instead, because if document.readyState isn't 'complete' yet, then we are guaranteed that the final readystatechange event hasn't fired yet, so it's safe to wait for it.

Fixes #60

Copy link
Member

@tomayac tomayac left a comment

Choose a reason for hiding this comment

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

LGTM, approval

@guillaumejenkins guillaumejenkins merged commit d331e6d into main May 20, 2021
@guillaumejenkins guillaumejenkins deleted the gujen-fix-init-event branch May 20, 2021 15:42
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.

Demo doesen't work in firefox
2 participants