Comments (7)
@garronej I apologize, I've added .withName to all styles in the project that use .withNestedSelectors and the errors no longer appear
from tss-react.
Hello @nphmuller,
Thank you for the detailed issue and the reproduction repository. It helped me discover a bug that wasn't directly tied to your issue.
Regarding your specific problem, the documentation was not clear enough about it, but in SSR setups, you must provide a unique ID to your useStyles using nested selectors:
-const useStyles = makeStyles<void, "icon">()(
+const useStyles = makeStyles<void, "icon">({ uniqId: "xDsMbr" })(
(_theme, _props, classes) => ({
link: {
// Removing this fixes the issue
[`& .${classes.icon}`]: {
color: "blue",
},
},
icon: {},
})
);
https://docs.tss-react.dev/nested-selectors#ssr
This solution is quite clunky; I also encourage you to try out the modern API instead of using makeStyles. It's much better in every way.
import { tss }Β from "tss-react/mui";
const useStyles = tss
.withName("ComponentWithIssue")
.withNestedSelectors<"icon">()
.create(({ theme, classes })=> ({
link: {
[`& .${classes.icon}`]: {
color: "blue",
},
},
icon: {},
}));
Giving a name is required in SSR setups when you use nested selectors. Anyway, giving a name to the useStyles is good practice since it makes finding the source code of the style from the browser debug tool much easier.
Don't forget to update to the latest version; I published a patch.
Best,
from tss-react.
Thank you so much for the lightning fast response. I should have suspected it was a usage error. It usually is π.
I'll make the necessary changes and I'll close this issue now.
Thanks again!
from tss-react.
No, no! You did good opening this issue, as I said revisiting the code made me found another bug!
Beside, the documentation about this wasn't clear enough.
from tss-react.
Hello, @garronej
I think this issue is still relevant in version 4.9.10. Every time nested selectors are used, both classes (nested selected & the class that uses it) lose their id during hydration.
Here are a couple of code samples that cause the error in NextJs with app directory
export const useStyles = tss
.withName("Header")
.withNestedSelectors<"menuItemActive">()
.create(({ theme, classes }) => ({
menuItem: {
height: 41,
display: "flex",
alignItems: "center",
justifyContent: "center",
borderRadius: 10,
textDecoration: "none",
boxSizing: "border-box",
padding: "0 22px",
"@media (hover: hover) and (pointer: fine)": {
[`:hover:not(.${classes.menuItemActive})`]: {
backgroundColor: theme.colors.basic[300],
},
},
},
menuItemActive: {
backgroundColor: theme.colors.secondary[200],
},
}));
export const useStyles = tss
.withName("MultiSelect")
.withNestedSelectors<"label">()
.create(({ theme, classes }) => ({
container: {
paddingTop: 12,
paddingBottom: 12,
display: "flex",
alignItems: "center",
columnGap: 6,
"@media (hover: hover) and (pointer: fine)": {
cursor: "pointer",
":hover": {
[`.${classes.label}`]: {
color: theme.colors.basic[600],
},
},
},
},
label: {},
}));
from tss-react.
Hello @ArtemAstakhov,
Sorry I can't reproduce.
I created a reproduction repo with your code. No issue
Screen.Recording.2024-05-09.at.02.24.45.mov
Can you please try do fork and modify the repo to make the issue your experiencing appear:
https://github.com/garronej/tss-issue-212
If I can reproduce I will adress it switfly.
from tss-react.
@ArtemAstakhov Great! Thank you for the update!
from tss-react.
Related Issues (20)
- <GlobalStyles /> don't work properly with next.js app folder HOT 7
- cannot Import multiple makeStyles HOT 1
- Use eslint rule to detect unused classed with imports HOT 2
- React 16.10.0 failed to install @ mui/material HOT 1
- How to use with css and styled apis. HOT 1
- yarn install with pnp mode complains about missing dependency @mui/material HOT 3
- NextJS/MUI/TSS - Cannot read properties of undefined (reading 'classes') HOT 3
- Hard reload after any file change HOT 2
- TssCacheProvider is not working when used with emotion cache and mui 5 HOT 6
- Using with Shadowed Web Components HOT 3
- Next.js: Applying augmentDocumentWithEmotionCache to document breaks AMP pages HOT 2
- The right way typing props when using withStyles HOT 3
- Invalid type for withStyles HOT 4
- Mantine integration
- Using `@import` rule within `<GlobalStyles />` component HOT 8
- `GlobalStyles` create multiple <style data-emotion="css-global">...<style> HOT 1
- Cannot read properties of undefined (reading 'length') in useGuaranteedMemo HOT 3
- MUI V5: Performance issues HOT 4
- "this" has been rewritten to "undefined" warning during the Rollup build (ESM) HOT 5
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 tss-react.