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

Avoid FOUC with FastBoot #16

Merged
merged 4 commits into from
Feb 4, 2018
Merged

Avoid FOUC with FastBoot #16

merged 4 commits into from
Feb 4, 2018

Conversation

alexlafroscia
Copy link
Owner

@alexlafroscia alexlafroscia commented Jan 28, 2018

Without explicit FastBoot support, the content would come down rendered from the server but no styles would be present yet. This caused an issue called "flash of unstyled content", or FOUC, that is common with server-side-rendered JavaScript apps that use CSS-in-JS solutions.

This PR introduces proper FastBoot support. The styles required for the initial render are computed on the server and baked into the initial payload, so that they're ready when the content is rendered by the browser. emotion is also "hydrated" with these styles, so that it avoids injecting them into the page a second time.

The technical approach to these things leans heavily on the patterns established by the first-party React SSR support, so I feel confident that I'm not using APIs that will break in the near future.

Additionally, emotion has an issue with the FastBoot environment that I landed emotion-js/emotion#550 to fix. This PR (once merged) will reference a version of emotion that includes that change.

TODOs

  • Update to emotion version 9.0.0-3 (or later)
  • Add some smoke tests for FastBoot to ensure that the server-side rendering doesn't break without me noticing
    • Probably can't test that the re-hydration works, but can at least test that the initial payload includes the CSS that's expected

Closes #2

Alex LaFroscia and others added 4 commits February 3, 2018 16:35
We don’t care about these errors, because all it means is that the stylesheet is not defined. We can just return the default empty object in those cases.

Other errors, however, we want to surface. This came up when `emotion` was throwing an error about needing access to the document.
Emotion 9 will be required for Fastboot support, because it will include the PR that I made to get around the document/window issue
@alexlafroscia
Copy link
Owner Author

Punting on tests due to this issue:

tomdale/ember-cli-addon-tests#157

I can't run the generator for an addon test because I overwrite the resolver.js and lack a way to tell the command to clobber the default file.

@alexlafroscia alexlafroscia merged commit cf16341 into master Feb 4, 2018
@alexlafroscia alexlafroscia deleted the fastboot-integration branch June 11, 2018 22:05
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.

Investigate Fastboot compatibility
1 participant