-
-
Notifications
You must be signed in to change notification settings - Fork 67
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 require cache busting whenever possible. #130
Conversation
This test demonstrates how each "layer" in an ember app is transpiling its own templates. Each is _supposed_ to be able to provide its own AST plugins, **but** this test shows how this falls down and fails. The current mechanism for registering AST plugins is fundamentally flawed. This forced us (long ago) to add some shenanigans to clear the require cache (to avoid this exact state leakage).
This avoids calling `registerPlugin` (and therefore mutating global state) but maintains support for custom AST plugins by passing for each compilation. This works for Ember 1.13 and higher.
776b554
to
73172f4
Compare
In order to stop the cache busting system, we need to: * Update the actual compilation code to pass in our custom options (done in a prior commit) * Ensure that **no one** is mutating the global list of plugins (if they are, then we will always get their plugins and therefore our compilation is "spoiled" by their AST plugins) * Avoid purging the `require.cache` when the requirements are met
5541bb6
to
b67b6e9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - this brings an end to an era. I still remember us debugging this originally, thanks for tackling this!
@@ -109,12 +187,24 @@ module.exports = { | |||
pluginCacheKey: pluginInfo.cacheKeys | |||
}; | |||
|
|||
if (this.legacyPluginRegistrationCacheBustingRequired !== false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the !== false
here makes it hard for my brain to read this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kk, ya I can fix that up
Ugh, this has bit rot a bit. Need to circle back and try to get this landed... |
The changes that landed in #660 + #661 (and emberjs/ember.js#19429) make this largely unneeded. At this point, we no longer purge the cache and can even remove the |
Generally speaking, ember-cli allows each "addon layer" in the app that is transpiling its own templates. Each layer is supposed to be able to provide its own AST plugins without affecting the others. Unfortunately, the implementation of
Ember.HTMLBars.registerPlugin
mutates a single shared module scope array to track which plugins should be ran.In order to allow the layered approach mentioned above, ember-cli-htmlbars was forced to invalidate the
require.cache
anddelete
various things off of theglobal
object. Requiringember-template-compiler.js
(~1.2mb) many times (once for the project and again for each addon that depends onember-cli-htmlbars
) is a non-trivial percentage of every app's build time and overall memory.This PR begins the process of removing that manual cache invalidation, in favor of better APIs provided by Ember (as of Ember 1.13 and higher).
In order to stop the manual cache invalidation but still provide the guarantees that each layer's AST plugins do not affect the others' we must still continue to invalidate the caches cache busting system if we detect that anyone in the system is using the global state mutation.
Specific changes in this PR:
Ember.HTMLBars.registerPlugin
), instead pass the plugins directly toEmber.HTMLBars.precompile
for each module.ember-cli-htmlbars
orember-cli-htmlbars-inline-precompile
that still uses global state mutation.require.cache
when the requirements are met.TODOs:
Future PR TODO: