Avoid require cache busting whenever possible.#130
Closed
Conversation
added 2 commits
October 11, 2018 10:11
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
added 2 commits
October 11, 2018 16:14
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
stefanpenner
approved these changes
Oct 12, 2018
Contributor
stefanpenner
left a comment
There was a problem hiding this comment.
LGTM - this brings an end to an era. I still remember us debugging this originally, thanks for tackling this!
4 tasks
stefanpenner
requested changes
Oct 2, 2019
| pluginCacheKey: pluginInfo.cacheKeys | ||
| }; | ||
|
|
||
| if (this.legacyPluginRegistrationCacheBustingRequired !== false) { |
Contributor
There was a problem hiding this comment.
the !== false here makes it hard for my brain to read this
Member
Author
|
Ugh, this has bit rot a bit. Need to circle back and try to get this landed... |
This was referenced Feb 25, 2021
Member
Author
|
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.registerPluginmutates 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.cacheanddeletevarious things off of theglobalobject. 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.precompilefor each module.ember-cli-htmlbarsorember-cli-htmlbars-inline-precompilethat still uses global state mutation.require.cachewhen the requirements are met.TODOs:
Future PR TODO: