Giter Site home page Giter Site logo

Comments (7)

ArtemAstakhov avatar ArtemAstakhov commented on September 23, 2024 1

@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.

garronej avatar garronej commented on September 23, 2024

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.

nphmuller avatar nphmuller commented on September 23, 2024

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.

garronej avatar garronej commented on September 23, 2024

@nphmuller,

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.

ArtemAstakhov avatar ArtemAstakhov commented on September 23, 2024

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.

garronej avatar garronej commented on September 23, 2024

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.

garronej avatar garronej commented on September 23, 2024

@ArtemAstakhov Great! Thank you for the update!

from tss-react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.