-
Notifications
You must be signed in to change notification settings - Fork 2
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
Updating Template before CSS causes template to not pick up scoped class name #90
Comments
Something else to note, if you redo the first few steps without adding another div, but adding a second class to the second div, the scoped class is applied. But then if you remove the duplicate class name, the element returns back to the previous state with no scoped class. I'm assuming it's likely a cached key issue (with the single "bar" class):
// hbs
<div class="foo">foo</div>
// css
.foo {
color: red;
}
// html output
<div class="foo">foo</div>
// hbs
<div class="foo">foo</div>
<div class="bar">bar</div>
// html output
<div class="foo_ee3b6cad0">foo</div>
<div class="bar">bar</div>
// css
.foo {
color: red;
}
.bar {
color: green;
}
// html output
<div class="foo_ee3b6cad0">foo</div>
<div class="bar">bar</div>
// hbs
<div class="foo">foo</div>
<div class="bar bar">bar</div>
// html output
<div class="foo_ee3b6cad0">foo</div>
<div class="bar_ee3b6cad0 bar_ee3b6cad0">bar</div>
// hbs
<div class="foo">foo</div>
<div class="bar">bar</div>
// html output
<div class="foo_ee3b6cad0">foo</div>
<div class="bar">bar</div> Definitely appears to be cache key related, if you revert an element to the state it was before a class was defined, it undoes the scoped class, essentially reverting to the previous state when the class didn’t exist. |
After running into the issue again, I decided to do some digging and discovered that part of the issue is that the babel plugin only runs on hbs changes. There may be some order of operations happening with making the hbs change first before the class exists. Adding the class to the css doesn't run the babel plugin, and finally trying to resave the hbs file doesn't re-trigger the babel plugin. I am assuming that is due to some caching, which I have verified is happening by returning the file to a state that had previously been processed. Making a new change (that has never been saved and processed) and saving the hbs file will eventually retrigger the scoped-babel-plugin. So ultimately, the issue appears to be:
I'm not sure exactly what the answer is, but that appears to be the source of the issue. |
fixes #90 by adding postProcess hook to scoped-css-preprocessor to break cache for associated template files
Pinning and re-opening because the implemented solutions has caused some confusion, and the problem goes away if we adopt a solution similer to https://github.com/cardstack/glimmer-scoped-css (have everything in one file) |
A way to solve this (that we talked about at the onsite), was being explored here, but we can't currently pursue that implementation because it would mean we lose HOT loading of CSS, which is a requirement for us internally due to how numerous our dozens of app MB are. We may have to
Right now, our scoped-css approach is at risk because we don't have parity between embroider and non-embroider. See here for details #120 |
I've observed some funky behavior within the new addon, specifically around creating elements with a style class before the class exists, the template never receives the scoped class definition, even after the class has been created and the template has been changed. Additional classes don't necessarily trigger a scoped class name update, only in certain cases where the element has some specific changes to it.
foo
foo
bar
bar
The second div with
bar
never updates, even though a newer div with the same style does. Definitely appears to be some sort of caching issue, hopefully these steps help!The text was updated successfully, but these errors were encountered: