Skip to content
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(ui): Storybook's <DocsContainer /> overwriting theme object #29770

Merged
merged 1 commit into from
Nov 5, 2021

Conversation

vuluongj20
Copy link
Member

Storybook's <DocsContainer /> implements its own theme context. In the current configuration, that theme context is a descendant of the custom theme context that we implemented:

<ThemeProvider> // our custom theme context, from utils/theme.tsx
    <DocsContainer /> // DocsContainer and its own theme context
</ThemeProvider>

This means DocsContainer's theme object will overwrite any property in our theme object. This is a problem because both have the background property. Any component inside DocsContainer will see only DocsContainer's background and not ours:
Screen Shot 2021-11-03 at 4 57 42 PM

To fix this, we can move our custom ThemeProvider context inside DocsContainer, making it more specific and thus overwriting whatever value is in DocsContainer's theme. As a result, components inside DocsContainer will now get the correct theme values:
Screen Shot 2021-11-03 at 4 58 29 PM

Storybook's <DocsContainer /> implements its own theme context. In the current configuration, that theme context is a descendant of the custom context that we implemented:

<ThemeProvider> // our theme context
    <DocsContainer /> // DocsContainer and its own theme context
</ThemeProvider>

This means DocsContainer's theme context will overwrite any property in our custom theme. This is a problem because both contexts have the `background` property. DocsContainer's `background` is an object, while ours is a string value. Components inside DocsContainer cannot use our own `background` value because it is overwritten by DocsContainer.

Fix: Move our custom ThemeProvider inside DocsContainer, making it more specific.
@vuluongj20 vuluongj20 requested a review from billyvg November 4, 2021 00:36
<ThemeProvider theme={currentTheme}>{children}</ThemeProvider>
</DocsContainer>
<ThemeProvider theme={currentTheme}>
<TableOfContents />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok that this is not part of DocsContainer? This is a bit awk, but not a big deal

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be okay. DocsContainer is just a wrapper around the main content. There's another wrapper (#docs-root) surrounding both it and <TableOfContents />.

@vuluongj20 vuluongj20 merged commit d184f66 into master Nov 5, 2021
@vuluongj20 vuluongj20 deleted the vuluong/storybook-theme-overwrite branch November 5, 2021 18:32
@github-actions github-actions bot locked and limited conversation to collaborators Nov 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants