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

Ensure it works with Fastboot #60

Merged
merged 3 commits into from
Feb 3, 2020
Merged

Ensure it works with Fastboot #60

merged 3 commits into from
Feb 3, 2020

Conversation

mydea
Copy link
Contributor

@mydea mydea commented Feb 3, 2020

This PR restores FastBoot compatibility.
It is heavily inspired by https://github.com/adopted-ember-addons/ember-cli-ifa/pull/57/files.

There are basically two main issues that need to be worked around for FastBoot:

  1. We cannot load the asset map via document.querySelector(...), as document is not available in Node
  2. We cannot load the locale files (e.g. en.json) via XMLHttpRequest, as that is not available in Node

For 1.), I used the same approach as the one in the references PR to ember-cli-ifa, to build a custom module for Node which can be requested in FastBoot environment (this is encapsulated in the new utils/get-locale-asset-map.js file).

For 2.), we embed the actual locale file content in the asset map, instead of the path to the asset map, for the FastBoot module. This way, we avoid needing to make any Ajax requests in FastBoot environment.

FastBoot will also generate a package.json file in the output, which needs to be excluded from fingerprinting. This PR will automatically adjust the fingerprinting options to work with ember-l10n now, including adding json to fingerprint.extensions for you. The user is informed about any changes made to the configuration in the console, e.g.:

ember-l10n automatically adjusted the fingerprinting settings to work properly:
* added 'json' to fingerprint.extensions
* added 'package.json' to fingerprint.exclude

Note that it does not actually add FastBoot as a dev dependency, and does not add any FastBoot tests for now. I did install FastBoot locally and tried it, to ensure it works as expected (which it did for me).

Fixes #59

@mydea mydea requested a review from arm1n February 3, 2020 12:42
Francesco Novy added 3 commits February 3, 2020 13:43
The `didReceiveAttrs` was sometimes run multiple times, e.g. in Fastboot, leading to issues there. A CP will automatically use caching and not re-run if the message doesn't change.
Note: The availableLocales CP in the dummy app triggered an immediate re-render, which tripped up FastBoot.
This will ensure that if fingerprinting is enabled:

* It will also fingerprint .json files
* It will NOT fingerprint package.json, if FastBoot is used (this is generated by FastBoot on the fly)

It also means that users will not need to adjust their config anymore.
For clarity, we log any changes to the configuration in the console.
@mydea mydea changed the title Fastboot Ensure it works with Fastboot Feb 3, 2020
@mydea mydea merged commit 70e35d9 into master Feb 3, 2020
@mydea mydea deleted the fastboot branch February 3, 2020 13: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.

Does not work with fastboot
2 participants