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

Color Palette Critical issue in 6.1 #45569

Closed
mdmag opened this issue Nov 5, 2022 · 12 comments
Closed

Color Palette Critical issue in 6.1 #45569

mdmag opened this issue Nov 5, 2022 · 12 comments
Labels
Needs Testing Needs further testing to be confirmed. [Package] Components /packages/components [Status] Needs More Info Follow-up required in order to be actionable.

Comments

@mdmag
Copy link

mdmag commented Nov 5, 2022

Description

We were using ColorPalette component which we import from @wordpress/components
colors prop have been optional until 6.1 release
6.1 release crashes our app because it suppose that color prop is required.

Step-by-step reproduction instructions

1- Import ColorPalette from "@wordpress/components"
2- Don't pass colors prop
3- You will notice a javascript error

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@skorasaurus skorasaurus added [Package] Components /packages/components [Status] Needs More Info Follow-up required in order to be actionable. Needs Testing Needs further testing to be confirmed. labels Nov 7, 2022
@skorasaurus
Copy link
Member

Hi,

Thanks for reporting; could you provide a code example of with the error occurring as well as the error message as well ; I am not able to reproduce any error on a test case where I have the following in my edit.js

import { ColorPalette } from "@wordpress/components";
import { useState } from "@wordpress/element";


const MyColorPalette = () => {
	const [color, setColor] = useState("#f00");

	return <ColorPalette value={color} onChange={(color) => setColor(color)} />;
};

@ndiego
Copy link
Member

ndiego commented Nov 8, 2022

@ciampo I see you have done a decent amount of work on the ColorPalette component in the past few months. Any ideas on this one?

@Mamaduka
Copy link
Member

Mamaduka commented Nov 8, 2022

Here's PR that aims to fix issue #45566.

I think we can use optional chaining as proposed in PR or set the default for colors params, as it's documented.

Cc @mirka

@mirka
Copy link
Member

mirka commented Nov 8, 2022

Ah, I think I understand what's going on now! The Gutenberg code in WP 6.1 is not up to date with our documentation, which is always in line with trunk.

In trunk, colors is documented as optional and it will not crash. In WP 6.1, colors is still required and will crash.

This change happened in dbbcc6e. So if you check the commit before that (6ee2a49), the docs say that colors is required, and will crash.

@Mamaduka
Copy link
Member

Mamaduka commented Nov 8, 2022

@mirka, the missing required colors param wasn't crashing in 6.0 because we were using lodash.map, which won't trigger an error if a variable is undefined.

https://github.com/WordPress/gutenberg/blob/release/6.0/packages/components/src/color-palette/index.js#L29

Should we consider this as a breaking change?

I understand that it was documented as required, but people often ignore docs.

@griffbrad
Copy link

@tyxla This looks like a case where lodash was maybe being overly "forgiving" with types previously and covering up the issue. We should probably guard against this case to preserve the older behavior.

@tyxla
Copy link
Member

tyxla commented Nov 8, 2022

Thanks for the ping! I'm going to take a look shortly.

@mirka
Copy link
Member

mirka commented Nov 8, 2022

Should we consider this as a breaking change?

Hard to say in this specific case, but definitely the type of change we should be careful of when removing lodash dependencies!

As for this particular issue, it has been back to the previous behavior since #44632, with docs updated to mark the prop as optional. It should also be guarded against future regressions of the sort, thanks to it being in TypeScript now.

So the immediate action item here would be to include #44632 in the next release (not sure if there's a cherry picking situation going on for the patch releases).

@Mamaduka
Copy link
Member

Mamaduka commented Nov 8, 2022

Thank you, @mirka!

I will add #44632 to the WP 6.1.1 board and cherry-pick it for the minor release.

@Mamaduka Mamaduka moved this from Triage to In Progress in WordPress 6.1.x Editor Tasks Nov 9, 2022
@tyxla
Copy link
Member

tyxla commented Nov 9, 2022

From what I understand, there isn't anything else to be done here, other than cherry-picking #44632. Unless y'all think we need additional undefined handling?

@Mamaduka
Copy link
Member

Mamaduka commented Nov 9, 2022

That's my understanding as well, @tyxla.

@Mamaduka
Copy link
Member

The fix was backported into WP 6.1.1. I'll close the issue.

@Mamaduka Mamaduka moved this from In Progress to Done in WordPress 6.1.x Editor Tasks Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Testing Needs further testing to be confirmed. [Package] Components /packages/components [Status] Needs More Info Follow-up required in order to be actionable.
Projects
No open projects
Development

No branches or pull requests

7 participants