-
Notifications
You must be signed in to change notification settings - Fork 798
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
fix(style): fixes to watching nested and multiple styles on Stencil components #5244
Conversation
|
Path | Error Count |
---|---|
src/dev-server/index.ts | 37 |
src/mock-doc/serialize-node.ts | 36 |
src/dev-server/server-process.ts | 32 |
src/compiler/prerender/prerender-main.ts | 22 |
src/testing/puppeteer/puppeteer-element.ts | 22 |
src/runtime/client-hydrate.ts | 20 |
src/screenshot/connector-base.ts | 19 |
src/runtime/vdom/vdom-render.ts | 17 |
src/compiler/config/test/validate-paths.spec.ts | 16 |
src/dev-server/request-handler.ts | 15 |
src/compiler/prerender/prerender-optimize.ts | 14 |
src/compiler/sys/stencil-sys.ts | 14 |
src/compiler/transpile/transpile-module.ts | 14 |
src/sys/node/node-sys.ts | 14 |
src/compiler/prerender/prerender-queue.ts | 13 |
src/compiler/sys/in-memory-fs.ts | 13 |
src/runtime/connected-callback.ts | 13 |
src/runtime/set-value.ts | 13 |
src/compiler/output-targets/output-www.ts | 12 |
src/compiler/transformers/test/parse-vdom.spec.ts | 12 |
Our most common errors
Typescript Error Code | Count |
---|---|
TS2345 | 366 |
TS2322 | 362 |
TS18048 | 224 |
TS18047 | 99 |
TS2722 | 37 |
TS2532 | 26 |
TS2531 | 23 |
TS2454 | 14 |
TS2352 | 12 |
TS2790 | 11 |
TS2769 | 8 |
TS2538 | 8 |
TS2344 | 6 |
TS2416 | 6 |
TS2493 | 3 |
TS18046 | 2 |
TS2684 | 1 |
TS2430 | 1 |
Unused exports report
There are 14 unused exports on this PR. That's the same number of errors on main, so at least we're not creating new ones!
Unused exports
File | Line | Identifier |
---|---|---|
src/runtime/bootstrap-lazy.ts | 21 | setNonce |
src/screenshot/screenshot-fs.ts | 18 | readScreenshotData |
src/testing/testing-utils.ts | 198 | withSilentWarn |
src/utils/index.ts | 145 | CUSTOM |
src/utils/index.ts | 269 | normalize |
src/utils/index.ts | 7 | escapeRegExpSpecialCharacters |
src/compiler/app-core/app-data.ts | 25 | BUILD |
src/compiler/app-core/app-data.ts | 115 | Env |
src/compiler/app-core/app-data.ts | 117 | NAMESPACE |
src/compiler/fs-watch/fs-watch-rebuild.ts | 123 | updateCacheFromRebuild |
src/compiler/types/validate-primary-package-output-target.ts | 61 | satisfies |
src/compiler/types/validate-primary-package-output-target.ts | 61 | Record |
src/testing/puppeteer/puppeteer-declarations.ts | 485 | WaitForEventOptions |
src/compiler/sys/fetch/write-fetch-success.ts | 7 | writeFetchSuccessSync |
ce9d728
to
7a1b77e
Compare
superseeds #3110 STENCIL-1049
7a1b77e
to
878138f
Compare
@christian-bromann For a detailed look at the issue, please refer to the repository linked below: |
@a7medm7med thanks for the feedback, I will look into this starting next week! |
@a7medm7med I am not able to reproduce this. If I install the project and run |
@christian-bromann, kindly follow these steps to address the issue:
If you encounter any difficulties reproducing the issue, I am prepared to provide a video demonstration for clarification. Please let me know if further assistance is required. |
VID-20240116-WA0000.mp4 |
@a7medm7med can you verify if this is an identical issue to what you have reported in #4130? |
@christian-bromann |
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.
In the future, can you please separate these into separate PRs? Based on the PR summary, we're fixing three separate issues here:
- Multiple style urls aren't recognised in watch mode
- nested files are not applied in watch mode
- Styles outside of project dir aren't picked up by watcher
While the changelist is small in size, I've found that it helps immensely in Stencil to be able to differentiate which changes are for which fixes - this helps with git bisect
ing, backing out changes if needed, and git blame
(to figure out why something is needed/where it came from). No action required here (I think I have a good idea as to what's going on here based on yesterday's jam session), just something to keep in mind for future efforts.
@rwaskiewicz thanks for the feedback. I addressed the comments. |
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.
I found an issue with the test case - Styles outside of project dir aren't picked up by watcher. I wasn't able to verify this fix for this scenario. I tried to create something myself to make sure I wasn't misunderstanding the repro, and hit the same error with both the instructions in the PR summary and those below:
- I created a new Stencil component starter with
npm init stencil@latest component css-test
in my/tmp
directory, and installed a local build of this branch based on f020caf (npm run clean && npm ci && npm run build && npm pack
) - I created
/tmp/outside.css
, whose content is:
:host {
color: red;
}
(also in the lower right hand pane in the terminal in the video below).
3. I updated the styles for my-component.tsx
to use the new styles outside of src
:
@Component({
tag: 'my-component',
- styleUrl: 'my-component.css',
+ styleUrls: ['my-component.css', '../../../../outside.css'],
shadow: true,
})
- I started the dev server,
npm start
- On updating
/tmp/outside.css
(changing the value forcolor
), it appears there's a refresh needed for styles to propagate:
Screen.Recording.2024-01-19.at.10.21.09.AM.mov
/** | ||
* add file to watch list if it is outside of the `srcDir` config path | ||
*/ | ||
if (config.watch && (id.startsWith('/') || id.startsWith('.')) && !id.startsWith(config.srcDir)) { |
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.
I think I'd personally lean toward a config option that allows devs to specify additional files/dirs to watch (like a glob pattern array). But, if I'm the only one then this works too!
@rwaskiewicz I found this error be particularly only when you link the Stencil project. Will look into fixing it. |
@rwaskiewicz found a fix, please try again. |
@christian-bromann For posterity, I was able to replicate this with a dev build ( |
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.
Prettier is failing - non-blocking though for this approval.
I don't have a strong opinion on whether a user should specify the directory or not. I'm OK with trying this approach (autodiscovery) out for now as I think that's what folks will come to expect. If we can find evidence it's a big footgun, we can always revisit
This patch has been released as a part of today's Stencil v4.11.0 release. |
This works perfectly so far for components, thanks! One problem I'm noticing is |
Interesting, that seems like a related but somewhat new issue. Mind raising a new issue for this with some detailed description of what you would expect and how it is actually behaving? From there we can inject this into our backlog and address accordingly. Thank you! |
This PR contains a set of small optimizations and bugfixes. I originally wanted to keep them in separate PRs but then found that they were small enough to be combined in one. The following issues get addressed:
Multiple style urls aren't recognised in watch mode
fixes #5251
When a component is bundled with multiple css files attached to it, the output will look as following:
From this Stencil creates a style tag within the shadow DOM to enable style HMR and injects the combined styles of the component
cmp.style
. Now when we update one CSS file, we push the update to the build contextbuildCtx.stylesUpdated
which will cause in replacing the content with what is instylesUpdated
. Unfortunately, when we change one file, we only get the update content of that file and not the combined styles.The patch stores the transform results of styles and is able to send a concatenation of them to the application.
Changes were applied in
src/compiler/bundle/ext-transforms-plugin.ts
Review Guide
To review this change:
git clone https://github.com/a7medm7med/stencil-bug
cd stencil-bug && npm i
npm start
src/components/button/button.text.scss
chnage color fromred
to e.g.blue
and verify that: background color is reseted and only styles fromsrc/components/button/button.text.scss
are applied to the pageto verify fix:
npm i @stencil/core@4.9.1-dev.1705446396.3c9fd4d
src/components/button/button.text.scss
and verify that background color remains red 🎉nested files are not applied in watch mode
fixes #2635
fixes #2741
fixes #1908
fixes #1388
it also:
closes #1909 (attempt to fix this bug in a different way which turned out to be incorrect)
If a component references an external style, e.g.:
or a global style is defined which imports another sass file:
then changes in
foo.scss
will not be recognised and user has to restart the dev server.Changes applied in
src/compiler/plugin/plugin.ts
fix this problem. They were adopted from #3110 and basically just add detected file dependencies to the transform result.Review Guide
To review this change:
git clone git@github.com:emily-ut/stencil-playground.git
cd stencil-playground
git checkout bug-scss-watcher
npm i
npm start
src/global/theme/theme.wireframe.scss
to a different color, verify that background color doesn't changeto verify fix:
npm i @stencil/core@4.9.1-dev.1705446396.3c9fd4d
src/global/theme/theme.wireframe.scss
to a different color, verify that background now gets updated correctlt 🎉Styles outside of project dir aren't picked up by watcher
Currently we add only the files that are within
config.srcDir
to our watch process. If a file is outside of that directory, it won't get picked up. As a fix I added a check to theextTransformsPlugin
which touches all styles that are used by any of the components and will add a style if the path is relative or absolute and not within thesrcDir
.Some considerations:
Review Guide
To review this change:
git clone git@github.com:James-Wilkinson-git/stencil-bug.git
cd ./stencil-bug/stencil-install/stencil
npm i
npm start
./stencil-bug/shared-style/my-component.scss
to a different color, verify that background color doesn't changeto verify fix:
cd ./stencil-bug/stencil-install/stencil
npm i @stencil/core@4.9.1-dev.1705446396.3c9fd4d
./stencil-bug/shared-style/my-component.scss
to a different color, verify that background now gets updated correctlt 🎉