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 editor colors for themes not loading color palettes #22356

Merged
merged 5 commits into from
Jul 6, 2020

Conversation

youknowriad
Copy link
Contributor

closes #21931

While ideally themes should load their palette styles in the editor to match the frontend, this PR restores the inline styles that were previously applied on the editor to avoid regressions.

The downside here is that there's a hook that has a very small but non-negligible impact on performance.

Testing instructions

  • Use a theme that doesn't load its palette on the editor (2019)
  • Make sure that when you use palette colors, the colors apply properly.

@youknowriad youknowriad added [Type] Bug An existing feature does not function as intended [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. labels May 14, 2020
@youknowriad youknowriad self-assigned this May 14, 2020
@github-actions
Copy link

github-actions bot commented May 14, 2020

Size Change: +142 B (0%)

Total Size: 1.13 MB

Filename Size Change
build/block-editor/index.js 109 kB +142 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.62 kB 0 B
build/api-fetch/index.js 3.4 kB 0 B
build/autop/index.js 2.82 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 7.16 kB 0 B
build/block-directory/style-rtl.css 944 B 0 B
build/block-directory/style.css 945 B 0 B
build/block-editor/style-rtl.css 10.7 kB 0 B
build/block-editor/style.css 10.7 kB 0 B
build/block-library/editor-rtl.css 7.62 kB 0 B
build/block-library/editor.css 7.62 kB 0 B
build/block-library/index.js 130 kB 0 B
build/block-library/style-rtl.css 7.78 kB 0 B
build/block-library/style.css 7.79 kB 0 B
build/block-library/theme-rtl.css 728 B 0 B
build/block-library/theme.css 729 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 48.2 kB 0 B
build/components/index.js 198 kB 0 B
build/components/style-rtl.css 15.8 kB 0 B
build/components/style.css 15.8 kB 0 B
build/compose/index.js 9.65 kB 0 B
build/core-data/index.js 11.4 kB 0 B
build/data-controls/index.js 1.29 kB 0 B
build/data/index.js 8.44 kB 0 B
build/date/index.js 5.47 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 569 B 0 B
build/dom/index.js 3.19 kB 0 B
build/edit-navigation/index.js 9.97 kB 0 B
build/edit-navigation/style-rtl.css 1.02 kB 0 B
build/edit-navigation/style.css 1.02 kB 0 B
build/edit-post/index.js 304 kB 0 B
build/edit-post/style-rtl.css 5.57 kB 0 B
build/edit-post/style.css 5.57 kB 0 B
build/edit-site/index.js 16.6 kB 0 B
build/edit-site/style-rtl.css 3.03 kB 0 B
build/edit-site/style.css 3.03 kB 0 B
build/edit-widgets/index.js 9.33 kB 0 B
build/edit-widgets/style-rtl.css 2.45 kB 0 B
build/edit-widgets/style.css 2.45 kB 0 B
build/editor/editor-styles-rtl.css 537 B 0 B
build/editor/editor-styles.css 539 B 0 B
build/editor/index.js 44.8 kB 0 B
build/editor/style-rtl.css 3.78 kB 0 B
build/editor/style.css 3.77 kB 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 7.73 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 2.13 kB 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/is-shallow-equal/index.js 710 B 0 B
build/keyboard-shortcuts/index.js 2.51 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.12 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/media-utils/index.js 5.3 kB 0 B
build/notices/index.js 1.79 kB 0 B
build/nux/index.js 3.4 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/primitives/index.js 1.5 kB 0 B
build/priority-queue/index.js 788 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/rich-text/index.js 14 kB 0 B
build/server-side-render/index.js 2.68 kB 0 B
build/shortcode/index.js 1.69 kB 0 B
build/token-list/index.js 1.28 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.85 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

Copy link
Member

@jorgefilipecosta jorgefilipecosta left a comment

Choose a reason for hiding this comment

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

LGTM 👍 We have a failing test on travis but does not looks related.

( BlockListBlock ) => ( props ) => {
const { name, attributes } = props;
const { backgroundColor, textColor } = attributes;
const { colors } = useSelect( ( select ) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tracked the test failure locally. I don't understand why it happens yet but it seems that commenting/removing the useSelect solves the issue. That's very weird. Any ideas why a useSelect call without impact on the rendered component would break tests here cc @aduth @epiqueras @jorgefilipecosta

Copy link
Member

Choose a reason for hiding this comment

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

What are the symptoms of the issue? (What do you see?)

Based on what I see here, it's not really clear what issue there should be. Is it fair to say "without impact on the rendered component" if colors is used below in determining which props to assign?

I doubt it has any impact on fixing the issue, but a suggestion I might have here is it could be good to avoid the subscription incurred by useSelect until after the point where it's known whether the early return is reached, by creating a separate component which handles the logic after the early return and contains the hook.

I guess unless we figure that most common blocks will support colors, in which case it's probably not much an optimization.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with the proposal, it will fix the test but potentially hide an issue because the test fails even if we don't apply any style (the early return)

And I don't the symptoms are basically the test failure: it seems like something related to focus maybe cause the "Third paragraph" is not written.

Copy link
Contributor

Choose a reason for hiding this comment

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

It sounds like a race condition with the subscriptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR is an important fix, I'm tempted to apply @aduth's fix in order to land it even if it hides the failure.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not a bad idea. That's the recommended way to deal with conditional hooks, regardless of tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, no ideally we don't remount the block when applying a color so we shouldn't bail early here (maybe just for the support check)

Copy link
Member

Choose a reason for hiding this comment

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

Aren't we already rerendering? For each path, a different instance of BlockListBlock is returned. It should still work otherwise though. Maybe worth looking at after beta 1?

@oandregal
Copy link
Member

oandregal commented May 21, 2020

Hey, this is a difficult situation 😞

Trying to recap what has happened here, for the record:

  • At some point in the past, the Block Editor makes custom presets (color, font-size, gradient) work by adding a class and inline styles to the block, while in the front we don't use inline styles.
  • Themes declare custom presets. However, some of them don't enqueue the corresponding classes for those presets in the editor. By chance, presets in the editor still work because Gutenberg added inline styles in addition to the classes.
  • We removed the inline styles to make the editor as much similar to the front-end as possible, so themes can do fewer things.
  • Themes that don't enqueue the styles for their custom presets realize that the styles for their presets in the editor aren't present (so some things aren't working now).

Would this be a faithful representation of what happened here?

If it is, I wouldn't consider this a Block Editor regression, but a theme bug that was only uncovered recently. Note that this fix is also incomplete: for example, it won't fix the situations where themes want to be smart about things (like setting both the text and background color at the same time) and can introduce subtle errors in that case. TwentyTwenty does this.

I reckon we under-communicated the removal of inline styles. Do you think is still there a chance we can handle this by publishing a dev note?

I understand this is a nuanced situation and why we feel like we need to cover for themes here. So, if we do this, I'd say that:

@youknowriad
Copy link
Contributor Author

youknowriad commented May 21, 2020

I reckon we under-communicated the removal of inline styles. Do you think is still there a chance we can handle this by publishing a dev note?

Judging by the number of impacted themes, I don't think so. That said, this becomes useless when we provide presets styles... (experimental-theme.json)

@youknowriad
Copy link
Contributor Author

Did we use inline styles for font sizes as well in the past? If so I agree we should do the same but I'm not sure it was the case.

@oandregal
Copy link
Member

Judging by the number of impacted themes, I don't think so.

👍

That said, this becomes useless when we provide presets styles... (experimental-theme.json)

Agreed. One of the advantages of a "managed CSS" approach.

Did we use inline styles for font sizes as well in the past? If so I agree we should do the same but I'm not sure it was the case.

I was under the impression we did, but I'll check tomorrow morning.

@oandregal
Copy link
Member

Yeah, font-sizes did the same. Haven't looked at the code for this PR, but, if this is ready, perhaps it can land and we do font-sizes separately. You want to do that or should I help? I guess that's one that needs to land in the next release for coherence.

...propsB,
};

if ( propsA && propsB && propsA.className && propsB.className ) {
Copy link
Member

Choose a reason for hiding this comment

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

optional?.chaining?.here?

Copy link
Member

Choose a reason for hiding this comment

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

How can propsA be spread above if it can me nullish?

@youknowriad
Copy link
Contributor Author

@nosolosw I'd appreciate some help if possible for the font sizes.

I'm not going to merge yet though because it's quite clear that this PR makes the e2e tests more unstable than master for the moment.

};

return <BlockListBlock { ...props } wrapperProps={ wrapperProps } />;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
},
'withColorPaletteStyles'

@oandregal
Copy link
Member

@youknowriad I've created the equivalent PR for font sizes at #22668

@youknowriad youknowriad added Needs Dev Note Requires a developer note for a major WordPress release cycle and removed Needs Dev Note Requires a developer note for a major WordPress release cycle labels May 29, 2020
@kjellr kjellr mentioned this pull request Jun 24, 2020
6 tasks
@youknowriad youknowriad force-pushed the fix/themes-not-loading-palette branch from 99d6a8a to 84f06b1 Compare July 1, 2020 08:58
@ellatrix
Copy link
Member

ellatrix commented Jul 2, 2020

What's the status of this PR?

@youknowriad
Copy link
Contributor Author

The status is that it's ready but I haven't been able to find a way to make the e2e failure go. I'm having hard time understanding the reason for this failure.

@ellatrix ellatrix mentioned this pull request Jul 3, 2020
12 tasks
@ellatrix ellatrix force-pushed the fix/themes-not-loading-palette branch from 84f06b1 to bb0ae85 Compare July 3, 2020 13:11
: undefined,
};

let wrapperProps = props.wrapperProps;
Copy link
Member

Choose a reason for hiding this comment

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

This can be a constant?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Color settings not styling block in editor
6 participants