-
Notifications
You must be signed in to change notification settings - Fork 790
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
Styles from nested scss-files are not applied in watch mode #2635
Comments
As a work around:
Note: |
The workaround mentioned in #2635 (comment) doesn't seem to work for me. But I'm not using the latest Stencil version. Can anyone confirm if this is an existing issue in the latest Stencil version? |
@markcellus I'm using the 2.7.0 core and this issue brought me here. |
@markcellus @tuelsch I have been facing the same issue for months, and this was the workaround that worked for me, hope it is helpful. Ideally, it will be good if it is solved from stencil-sass. |
This is also what we experience and it isn't a great DX to always restart the build process to see the nested Sass changes reflected while development. It's a must to have a decent DX and should definitely be part of the default setup without tweaks or workarounds. Global nested/split Sass Files help immensly to structure the Sass code (normalize, typography, theming) instead of handling this within one big file. |
I just did some debugging and found a possible cause for this bug. This line checks if any of the changed style files are imported in the global style, but it looks for Not sure how to fix it though. Maybe not use the cached style to look for FYI The simplest workaround I found is simply saving the global scss file without any changes. |
hey! I decided to see if I could help with this issue but unfortunately I couldn't recreate. |
ok - I recreated using |
@johnjenkins I think the stencil's that are used in the opening post are quite old (1.something and 2.0.0-1). On the other hand, I still have the same issue: My component stylesheet
I tried the workaround and |
@tfrijsewijk but if you see the original video (here) / repo I posted - with that setup you describe I could't recreate. I could only recreate with |
Your video setup has a different directory layout (which also works for me, btw):
My setup has a more complex setup:
This is a Yarn Workspace and imports are done with // /packages/core/components/alert/alert.scss
@import "~@dso-toolkit/sources/src/components/alert/alert"; The |
OIC! |
I just found out the problem also exists when importing with relative paths: // before
@import "~@dso-toolkit/sources/src/components/alert/alert";
// after
@import "../../../sources/src/components/alert/alert"; I don't think it has anything to do with Yarn Workspaces or mono repos 🤔 It's as if Stencil figures out that a file is outside of the project and caches it really hard? |
👋 I wasn't able to reproduce the originally stated issue locally with the following diff --git a/stencil.config.ts b/stencil.config.ts
index 141c3d3..871126a 100644
--- a/stencil.config.ts
+++ b/stencil.config.ts
@@ -1,7 +1,11 @@
import { Config } from '@stencil/core';
+import { sass } from '@stencil/sass';
export const config: Config = {
namespace: 'nest',
+ plugins: [
+ sass()
+ ],
outputTargets: [
{
type: 'dist', Screen.Recording.2022-09-01.at.9.44.07.AM.mov@tfrijsewijk can you provide me with a minimal reproduction case to take a closer look? |
I'll see what I can do, but I think you're pretty close to my reproduction case already:
It's important to note that |
I want to clarify that there are two distinct issues that seem related, but I believe only one of them has been the focus of this discussion. The original issue pertains to using a SASS import in a component SCSS file. In the past, changing the contents of the imported SCSS file was not reflected in the browser. However, this issue appears to have been resolved as it's working for me in my project using Stencil 3. For more information, refer to ionic-team/stencil-sass#29. A related, but different issue that I've noticed is when using SCSS as a I believe this second issue, while related, is distinct from the original topic of this thread. It looks like the second issue is being worked on here #3110 |
Still, it doesn't work.😣 |
I think I'm using the latest version of Stencil. But it's still the problem -- it doesn't pick up changes in imported style files. |
I have this same issue, we recently moved our styles to a global scoped folder so they can be shared with our design system, stencil can read them on build, but can't watch them using relative paths that take you out of the stencil folder |
@James-Wilkinson-git @tfrijsewijk can someone provide a minimal reproducible example as I am unable to find any issues that are similar to what you've described. It would help me greatly to further investigate this. Maybe just make a PR to this repo: https://github.com/christian-bromann/stencil-style-repro |
Hi @christian-bromann here you go https://github.com/James-Wilkinson-git/stencil-bug To Reproduce, clone, cd into stencil-install/stencil, and install then This is an issue because of using stencil in a mono-repo setting, where the shared-styles are used in more than one place not just in the stencil component, such as if someone was to use just HTML of our stencil template they could import the styles, or when creating a global stylesheet to include where we are not using stencil. |
Thanks for providing the reproducible example. I was able to reproduce the problem and will move this into our backlog. |
Our solution has been to use a script that watches all of the scss files and then triggers an update to the "globalStyle" file: import { utimes, watch } from 'fs/promises';
const debounce = (f, ms = 100) => {
let timeout;
return (...args) => {
if (timeout !== undefined)
clearTimeout(timeout);
timeout =
setTimeout(() => {
timeout = undefined;
f(...args);
}, ms);
};
};
const src = new URL('./src/', import.meta.url);
const globalSassFile = new URL('./global/_global.scss', src);
const triggerGlobalSassUpdate = debounce(async () => {
const fakeModifiedTime = new Date();
await utimes(globalSassFile, fakeModifiedTime, fakeModifiedTime);
console.log('triggered global sass update');
});
for await (const event of watch(src, { recursive: true })) {
if (!event.filename)
continue;
const fileUrl = new URL(event.filename, src);
if (
fileUrl.pathname.endsWith('.scss') &&
fileUrl.pathname !== globalSassFile.pathname
)
triggerGlobalSassUpdate();
} However, this workaround stopped working in Stencil 4. Last time I tried, it did not work even if I manually edited a component's "styleUrl" file or the project's "globalStyle" file directly. The solution (slow) is to restart the build completely. |
@silvertech-daniel thanks for the feedback, I am currently revisiting a set of similar bugs and experienced similar behavior. We will ingest these issues into our backlog and address them accordingly now that we have validated the bugs and have a better idea about the impact on the user. |
The fix for this issue has been released as a part of today's Stencil v4.11.0 release. |
I;ve updated to 4.12.2 and the issue still remains. In our main project the watcher detects the changes but dosen't recompile the css, in the supplied bug protect, the watcher doesnt even detect the changes, was there a regression in 4.12 from 4.11? |
Installed 4.11.0 and confirmed that the watcher was still not picking up the scss from outside the project |
@James-Wilkinson-git mhm 🤔 I wonder how your project is set up. Mind providing a minimal reproducible example? I would be happy to take a look. |
@christian-bromann https://github.com/James-Wilkinson-git/stencil-bug I upgraded this to the latest and it was not working. |
@James-Wilkinson-git update |
I've run into this problem again. Stencil v4.13.0 and @stencil/sass v3.0.11 repo updated https://github.com/James-Wilkinson-git/stencil-bug/blob/main/stencil-install/stencil/package-lock.json |
@James-Wilkinson-git can you please open a new issue? |
Stencil versions:
I'm submitting a:
[ x ] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/
Current behavior:
If a component includes styles in a
.scss
file and that file in turn imports a second file, changes in the second file are not applied when running the dev server.Expected behavior:
Changes in nested files are applied when running the dev server
Steps to reproduce:
style2.scss
The watcher seem to trigger a new build and the dev server reloads the current page with components as expected, but the result does not include the changes. Reloading the page does not work either. The following seems to work as a workaround, but is annoying
@import
statement instyle.scss
It also seem to work when using
.css
files instead of.scss
Related code:
The text was updated successfully, but these errors were encountered: