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

Switch from rAF to Promise to fix FOUC in Safari #63

Merged
merged 1 commit into from
Dec 30, 2016

Conversation

ericf
Copy link
Contributor

@ericf ericf commented Dec 30, 2016

This fixes the FOUC issue in Safari by switching from requestAnimationFrame() to Promise#then() for the debouncing/batching mechanism. requestAnimationFrame() causes FOUC in Safari, setTimeout() causes FOUC in Chrome, while Promise#then() ensures micro task enqueueing of styles update before paint in Safari, Chrome, and Firefox.

This maintains the same semantics where only the latest call to updateOnClient() causes the rendering of styles by "cancelling" the previously created promises by making them noops.

Fixes #52
/cc @rauchg @nkzawa

@ericf ericf mentioned this pull request Dec 30, 2016
@nkzawa
Copy link
Contributor

nkzawa commented Dec 30, 2016

This is awesome ! I didn't notice this solution, thanks 👍

@nkzawa nkzawa merged commit e384734 into vercel:master Dec 30, 2016
@ericf ericf deleted the safari-fouc branch December 30, 2016 13:37
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.

FOUC in Safari
2 participants