Comments (4)
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):
- Create a template file containing a div with a single style
- Create an accompanying css file with the style for the div
// css
.foo {
color: red;
}
- Observe the rendered HTML does not have a scoped class name for
foo
// html output
<div class="foo">foo</div>
- Update the template file with a second div with a second single style
- Observe the rendered HTML after build has applied the scoped class name for
foo
// html output
<div class="foo_ee3b6cad0">foo</div>
<div class="bar">bar</div>
- Update the CSS file with a style definition for
bar
// css
.foo {
color: red;
}
.bar {
color: green;
}
- Observe the rendered HTML after build to see there has been no change to the scoped class definitions.
// html output
<div class="foo_ee3b6cad0">foo</div>
<div class="bar">bar</div>
- Add a second "bar" class to the second div and save the template file
- Observe the rendered HTML after build to see the scoped class definitions applied.
// html output
<div class="foo_ee3b6cad0">foo</div>
<div class="bar_ee3b6cad0 bar_ee3b6cad0">bar</div>
- Remove the second "bar" class from the second div and save the template file
- Observe the rendered HTML after build to see the bar scoped class definition has reverted.
// 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.
from ember-scoped-css.
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:
- Changes to css files do not trigger the scoped-babel-plugin
- Changes to hbs files that have already been processed by the babel plugin do not run again, which can cause a state where a css class will never be picked up unless the hbs file has a change that has not been processed by babel.
I'm not sure exactly what the answer is, but that appears to be the source of the issue.
from ember-scoped-css.
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)
from ember-scoped-css.
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
- give up on hot loading of CSS (to potentially solve this problem)
(this is because the CSS hot loading technique we use now is dependent on the legacy style pipeline, and we wouldn't be using that with "the fix" -- we'd make all CSS part of the module graph)
((I could be wrong here, and this may still need more exploration (and it's still worth doing that exploration, as we'll want a more robust solution when we get to vite anyway, something that plays nicer with "compile only what you see" --- but for now, I'm deprioritizing this exploration))) - or migrate to embroider/vite all at once (maybe via flag so folks can beta test)
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
We can re-gain that parity, but it'll just take some time.
from ember-scoped-css.
Related Issues (20)
- Add <style> tag for module-scoped CSS in gjs/gts files HOT 1
- Add <style> tag support *within* each <template> HOT 7
- Add to the Glimmer / <template> tutorial HOT 1
- Open Source this Addon HOT 3
- There should be configurable ignore css glob
- CSS layer should be configurable in a config
- Linting rule checking if selectors are used in the co-located template
- Scoping keyframes HOT 1
- Figure how to get rid of v1 addon / go full native JS HOT 2
- Dependency Dashboard
- Incompatible with `@embroider/addon-dev@v4` - transforms appear to not be working
- Repo breaks under ember-cli v5 HOT 1
- Migrate from `ember-template-tag` to `content-tag`
- Enhance embroider support.
- When using decorator-transforms, the rollup unplugin errors on "invalid syntax" HOT 1
- in GTS, `scoped-class` needs an import
- CSS preprocessor is not active if the app is named differently from the package.json#name field
- `scoped-class` is not a helper error when developing an addon component consumed by a primary application HOT 1
- Will not compile css assets for gts files in app/components HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ember-scoped-css.