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

Data: Use getThemeSupports() instead of getSettings() #23566

Closed
wants to merge 5 commits into from

Conversation

ockham
Copy link
Contributor

@ockham ockham commented Jun 29, 2020

Description

For determining if the current theme supports alignWide, replace calls of select( 'core/block-editor' ).getSettings().alignWide with select( 'core' ).getThemeSupports()[ 'align-wide' ], to reduce our dependency on the settings variable, and move to using the REST API instead.

This is a first iteration that's scoped to only tackle alignWide. It's supposed to serve as an RFC; if people think that this is a good idea, we can make the same kind of change to a number of other settings.

How has this been tested?

Verify that unit tests are green, and do some smoke testing of the affected code.

Specifically: Make sure you're using a theme that supports wide alignment (e.g. Twenty Twenty), and insert a Cover block in the editor. Select alignment options from the block toolbar, and verify that it includes wide and full alignment. Select one of those, publish the post, and verify that the alignment is correctly applied on the frontend. Then, try the same for a theme without wide alignment support.

Furthermore, verify that there are no other instances of alignWide that are still coming from select( 'core/block-editor' ).getSettings(), except in some .native.js files. (A number of remaining alignWide values are coming from invidual blocks' support of wide alignment, rather than themes'.)

Note

This PR doesn't touch code that's relevant for mobile apps (i.e. .native.js files), which introduced support for wide alignment only recently (in #24598). Moving forward, we should make sure that those files also use getThemeSupports() rather than getSettings() cc/ @geriux

Types of changes

Refactor.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@ockham ockham self-assigned this Jun 29, 2020
@github-actions
Copy link

github-actions bot commented Jun 29, 2020

Size Change: -1 B

Total Size: 1.2 MB

Filename Size Change
build/block-editor/index.js 128 kB +7 B (0%)
build/editor/index.js 45.6 kB -8 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.67 kB 0 B
build/api-fetch/index.js 3.41 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 8.5 kB 0 B
build/block-directory/style-rtl.css 953 B 0 B
build/block-directory/style.css 952 B 0 B
build/block-editor/style-rtl.css 11.1 kB 0 B
build/block-editor/style.css 11.1 kB 0 B
build/block-library/editor-rtl.css 8.64 kB 0 B
build/block-library/editor.css 8.64 kB 0 B
build/block-library/index.js 138 kB 0 B
build/block-library/style-rtl.css 7.59 kB 0 B
build/block-library/style.css 7.58 kB 0 B
build/block-library/theme-rtl.css 754 B 0 B
build/block-library/theme.css 754 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 47.7 kB 0 B
build/components/index.js 200 kB 0 B
build/components/style-rtl.css 15.5 kB 0 B
build/components/style.css 15.5 kB 0 B
build/compose/index.js 9.68 kB 0 B
build/core-data/index.js 12.3 kB 0 B
build/data-controls/index.js 1.29 kB 0 B
build/data/index.js 8.54 kB 0 B
build/date/index.js 31.9 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 4.48 kB 0 B
build/edit-navigation/index.js 11.7 kB 0 B
build/edit-navigation/style-rtl.css 1.16 kB 0 B
build/edit-navigation/style.css 1.16 kB 0 B
build/edit-post/index.js 305 kB 0 B
build/edit-post/style-rtl.css 6.26 kB 0 B
build/edit-post/style.css 6.25 kB 0 B
build/edit-site/index.js 19.4 kB 0 B
build/edit-site/style-rtl.css 3.06 kB 0 B
build/edit-site/style.css 3.06 kB 0 B
build/edit-widgets/index.js 12.1 kB 0 B
build/edit-widgets/style-rtl.css 2.46 kB 0 B
build/edit-widgets/style.css 2.45 kB 0 B
build/editor/editor-styles-rtl.css 492 B 0 B
build/editor/editor-styles.css 493 B 0 B
build/editor/style-rtl.css 3.81 kB 0 B
build/editor/style.css 3.81 kB 0 B
build/element/index.js 4.64 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 7.71 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.57 kB 0 B
build/is-shallow-equal/index.js 711 B 0 B
build/keyboard-shortcuts/index.js 2.52 kB 0 B
build/keycodes/index.js 1.95 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.32 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.41 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/rich-text/index.js 13.9 kB 0 B
build/server-side-render/index.js 2.77 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.27 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.13 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@ockham ockham mentioned this pull request Jun 29, 2020
6 tasks
@ockham ockham force-pushed the update/use-theme-supports-instead-of-settings branch from f9e0652 to ac423c9 Compare June 30, 2020 21:30
@ockham
Copy link
Contributor Author

ockham commented Jul 8, 2020

FYI @noahtallen since you're also removing initial state in #23775.

@ockham ockham force-pushed the update/use-theme-supports-instead-of-settings branch from ac423c9 to c80c1e7 Compare August 13, 2020 15:02
@ockham ockham force-pushed the update/use-theme-supports-instead-of-settings branch from c80c1e7 to 13cef91 Compare September 8, 2020 11:47
@@ -89,10 +89,10 @@ export function BlockAlignmentToolbar( {

export default compose(
withSelect( ( select ) => {
const { getSettings } = select( 'core/block-editor' );
const settings = getSettings();
const { getThemeSupports } = select( 'core' );
Copy link
Contributor

Choose a reason for hiding this comment

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

The block editor package shouldn't be relying on core-data it's a network/persistence agnostic package that allows creating third-party editors. It means, this should still use getSettings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to clarify, are you saying that @wordpress/block-editor should never fetch any information from the network? In conclusion, that would mean that it'll always depend on data passed through a global variable -- i.e. it'll be always tightly coupled to server-side provided information.

But wouldn't that mean it'd be impossible to ever implement a client-side only editor?

Copy link
Contributor

@youknowriad youknowriad Sep 8, 2020

Choose a reason for hiding this comment

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

But wouldn't that mean it'd be impossible to ever implement a client-side only editor?

For me it's the opposite, it means that it's easier to implement client-side only editors since it doesn't need to fetch anything.

Copy link
Member

Choose a reason for hiding this comment

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

So you would have to provide the settings object yourself via whatever method during load. That could be via PHP like in Gutenberg, but could be via your own API and init code

Copy link
Member

Choose a reason for hiding this comment

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

The current settings are something of a loosely related set of properties from different sources:

  • theme options (wide alignment, custom fonts/colors, post formats support, ...)
  • image sizes (commonly affected by the theme, too)
  • registered block patterns and categories
  • information about the edited post's lock state
  • some user options
  • some site options
  • customized labels for certain UI elements (write_your_story, enter_title_here)

That alone feels suboptimal and even third-party editor authors would probably appreciate the settings being split into multiple interfaces.

For an SPA-style browser client that talks to the server only through REST API, this means waiting for some 5+ REST requests to finish before even starting to initialize the editor.

Many of them are not even used by the block-editor package, like imageSizes or imageDimensions. These could be fetched just-in-time by the blocks that need them.

Is there agreement that the settings split described above is desirable? In other words, is the objection solely about the alignWide flag (directly used by the block-editor package)?

Copy link
Contributor

Choose a reason for hiding this comment

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

We should hold on doing any changes here because right now we're doing some changes to how these settings get the editor. Basically the source of truth for these will be theme.json in WordPress, they'll arrive to the block-editor in a single properly called "__experimentalFeatures" right now (subject to change). See this issue for more details #20588

Once we finish the migration there for all the properties, we'll be able to decide the best naming...

Copy link
Contributor

Choose a reason for hiding this comment

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

Other things like "patterns", "lock state", "upload handler"... are different though and I believe we don't have a good answer for these at the moment.

  • Patterns can become registration based like block types but I'm not sure we should commit to this for now, I'd like to give patterns more time to mature before making any formal JS APIs (they're experimental now)
  • the other configs that are not theme related are more "historical". I believe most of theme still make sense as block editor settings as their meaning can be different from one editor to another but If there's concrete suggestions to change one of these we can discuss it.

That said, I believe it's a hard rule that the "block-editor" package shouldn't do any REST API call on its own.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough. In that case, it'd be good if we could have a different mechanism to pass these options on the client side (after obtaining them through an external mechanism) -- maybe either as a prop, or maybe through a filter?

(Assuming that those settings are indeed invariant, and shouldn't be subject to change by the client, or at least not the block editor -- which makes sense for e.g. "theme supports" flags.)

@ockham
Copy link
Contributor Author

ockham commented Oct 12, 2020

Closing, see this discussion: #23566 (comment).

Bottom line (from #23566 (comment)):

In that case, it'd be good if we could have a different mechanism to pass these options on the client side (after obtaining them through an external mechanism) -- maybe either as a prop, or maybe through a filter?

@ockham ockham closed this Oct 12, 2020
@ockham ockham deleted the update/use-theme-supports-instead-of-settings branch October 12, 2020 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants