Skip to content

fix: add checks for preventing HSL colors from entering React state #9893

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

Merged
merged 5 commits into from
Sep 27, 2023

Conversation

Parkreiner
Copy link
Member

@Parkreiner Parkreiner commented Sep 27, 2023

Closes #9888

Changes

  • Updates the default state for AppearanceSettingsView to prevent HSL colors from accidentally entering the component
  • Adds some extra runtime checks when performing state transitions that validate color formatting and prevent HSL values from ever being able to enter the DashboardProvider's state
  • Adds tests for new functionality

Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

I didn't expect this to be a relatively large change, so let me challenge it.

@@ -30,13 +31,17 @@ export type AppearanceSettingsPageViewProps = {
preview: boolean,
) => void;
};

const fallbackBgColor = hslToHex(colors.blue[7]);
Copy link
Member

@mtojek mtojek Sep 27, 2023

Choose a reason for hiding this comment

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

KISS-related question: why do we need other changes in the PR? Did you identify any places where we can face HSL related issue?

EDIT:

I'm thinking about changes around the DashboardProvider.

Copy link
Member Author

@Parkreiner Parkreiner Sep 27, 2023

Choose a reason for hiding this comment

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

Yeah, KISS is definitely something I need to keep in mind more, but at least here, I feel like some kind of defensive changes (maybe not necessarily these) made sense.

The way I see it, there's a few risks right now:

  • DashboardProvider is already a top-level component that can be imported by anything else from the /components folder. It's also a context provider, so any importing component's sub-children would be able to use it indirectly, as well
  • The component is already being globally available to some degree because it's directly integrated into the RequireAuth component
  • So many constants in the codebase are set up as HSL strings for readability. We could get rid of these in favor of hex strings, but they're a lot less intuitive to work with

I felt like having the provider be in charge of validating incoming state changes would be the best way to prevent any future mismatches from popping up

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation! Sounds good to me 👍

@@ -30,13 +31,17 @@ export type AppearanceSettingsPageViewProps = {
preview: boolean,
) => void;
};

const fallbackBgColor = hslToHex(colors.blue[7]);
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation! Sounds good to me 👍

@Parkreiner Parkreiner enabled auto-merge (squash) September 27, 2023 19:24
@Parkreiner Parkreiner merged commit dcad8fd into main Sep 27, 2023
@Parkreiner Parkreiner deleted the mes/color-fix branch September 27, 2023 19:27
@github-actions github-actions bot locked and limited conversation to collaborators Sep 27, 2023
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.

Can't set service banner background color – background color sometimes changes from hex to HSL format
2 participants