-
Notifications
You must be signed in to change notification settings - Fork 526
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
Handle invalid color scheme names #1286
Conversation
🦋 Changeset detectedLatest commit: f0f8edc The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/primer/primer-components/HWjrVkvbSqeC5smKVHTpXSZam3xH |
return theme | ||
|
||
// Apply the first defined color scheme | ||
const defaultColorScheme = Object.keys(theme.colorSchemes)[0] |
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.
Non-blocking: I wonder if index 0
is magic-numbery? Though it may be our best option, since the Theme
type definition doesn’t require a default/fallback scheme to be designated (example below). 🤔
export type Theme = {
colorSchemes: {
default: { [key: string]: any }
[key: string]: any
}
[key: string]: any
}
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 agree that [0]
feels a little bit wrong here. Unfortunetly, we can't make any assumptions about the format of the theme
object without making a breaking change to the library. Let's move forward with this "incrementally correct" solution, and we can revisit TypeScript types for the theme
object later.
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.
Great change. Definitely makes sense to have a fallback here
Problem
If
ThemeProvider
is a passed an invalid color scheme name (e.g.<ThemeProvider dayScheme="foo">
), it could potentially break an entire application. We noticed this happening in an internal React application.Solution
This PR updates
ThemeProvider
to default to the first defined color scheme if it's passed an invalid color scheme name.