Skip to content

Improve DevTools CSS variables situation #22678

Closed

Description

@bvaughn

Related to this comment: #22660 (review)

The majority of DevTools theme colors are stored in packages/react-devtools-shared/src/constants:
https://github.com/facebook/react/blob/5cccacd131242bdea2c2fe4b33fac50d2e3132b4/packages/react-devtools-shared/src/constants.js#L75-L383

But some of them are also stored in packages/react-devtools-shared/src/devtools/views/root.css:
https://github.com/facebook/react/blob/5cccacd131242bdea2c2fe4b33fac50d2e3132b4/packages/react-devtools-shared/src/devtools/views/root.css#L2-L18

This is because of how they are referenced in a theme-agnostic way by Reach UI style overrides (for things like tooltips and context menus).

Can we do better here, at least to ensure they stay in sync? For example, can the ThemeProvider set the redundant values at the root level when the SettingsContext theme changes?

The primary goals of the current architecture are:

  1. Don't bleed styles into the global namespace (for our inline package users like Code Sandbox or Replay IO).
  2. Don't require awkward forced layout or re-renders for components that read style values programatically.

Activity

  1. jyash97 commented on Nov 2, 2021

    @jyash97
    Contributor

    I was looking into it and here is what I have in mind:

    Exposing all vars using style prop to reach-ui components which will be rendered in Portal (outside the rendered DOM), and we can create wrapper component or re-export the same component by passing all vars:

    // lib/reach-ui/MenuList.js
    import {MenuList} from 'react-ui'
    
    export const MenuList = ({children, ...props}) => <MenuList style={THEME_VARS} {...props}>{children}</MenuList>
    

    Example: https://codesandbox.io/s/quiet-fast-exg5q?file=/src/App.js

    children will have access to those CSS variables and we can style without adding custom variables in root.css

  2. bvaughn commented on Nov 3, 2021

    @bvaughn
    ContributorAuthor

    @jyash97 Oh! That's a very eloquent solution!

    So DevTools can just re-export the components we use, with the style decoration. Love it!

  3. jyash97 commented on Nov 3, 2021

    @jyash97
    Contributor

    Glad you liked it 😄

    Can I create a draft PR for the above solution ?

  4. bvaughn commented on Nov 3, 2021

    @bvaughn
    ContributorAuthor

    Yes, please do!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions