Make WordPress Core

Opened 103 minutes ago

Last modified 99 minutes ago

#66874 new defect (bug)

Editor: Classic themes without editor styles lose the default editor font

Reported by: ramonopoly Owned by:
Priority: normal Milestone: 7.3
Component: Editor Version: 7.0
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses:

Description

In the post editor, a classic theme with no theme.json and no editor styles shows the post content in the browser's default serif font at 16px. It should show the default editor styles: the system font at 18px.

Steps to reproduce

  1. Activate a classic theme that has no theme.json and does not call add_theme_support( 'editor-styles' ). A theme with only a style.css header and an empty index.php is enough.
  2. Create a post with a paragraph and open it in the block editor.
  3. Inspect the paragraph in the editor canvas.

Expected: the system font at 18px, from the defaultEditorStyles setting.

Actual: serif at 16px with line-height: normal.

Cause

Since #64408 and ​wordpress-develop PR 10623 (the backport of ​Gutenberg PR 73971, which enabled global styles for classic themes), get_block_editor_settings() adds the generated global stylesheet with '__unstableType' => 'theme' for every theme. The post editor only falls back to defaultEditorStyles when the settings contain no styles of that type, so it now treats every classic theme as having its own editor styles, and the defaults are never applied.

Before that change, themes without theme.json got a stylesheet typed 'base-layout', and the defaults were applied.

[65749] (#66762) restored the contents of defaultEditorStyles, which had become empty. That fixed the editor when "Use theme styles" is turned off, and the Customizer widgets editor. It does not fix this case, where the preference is on.

Proposed fix

In get_block_editor_settings(), when the context is the post editor with a post, the theme has no theme.json, and get_block_editor_theme_styles() returns nothing, add the defaultEditorStyles entries to the start of the styles setting, typed 'theme'.

  • Placed first, so global styles still override them.
  • Typed 'theme', so turning off "Use theme styles" still leaves only the default editor styles, with no duplicate.

This is the approach in ​Gutenberg PR 87629, which fixes ​Gutenberg issue 79815. This ticket is for the same change in core.

Change History (1)

This ticket was mentioned in ​PR #16330 on ​WordPress/wordpress-develop by ​@ramonopoly.


99 minutes ago
#1

  • Keywords has-patch has-unit-tests added

Backports ​https://github.com/WordPress/gutenberg/pull/87629.

What?

In the post editor, a classic theme with no theme.json and no editor styles shows the content in the browser's default serif font at 16px.

get_block_editor_settings() now adds the defaultEditorStyles entries to the start of the styles setting for these themes, typed 'theme'.

  • First in the list: global styles come after, so a font set in global styles still wins.
  • Typed 'theme': when "Use theme styles" is turned off, the editor drops them and uses defaultEditorStyles on its own, so the defaults are not doubled.

Why?

Since #64408, the generated global stylesheet is typed 'theme' for every theme. The post editor only uses defaultEditorStyles when there are no styles of that type, so it never applies them for classic themes.

Scope

Only the post editor: the core/edit-post context with a post. The widgets editor, the site editor and the /wp-block-editor/v1/settings endpoint (which uses core/edit-post without a post) are not changed.

Testing

npm run test:php -- --group 66874

Manual:

  1. Activate a classic theme with no theme.json and no add_theme_support( 'editor-styles' ). A theme with only a style.css header and an empty index.php is enough.
  2. Create a post with a paragraph and inspect the paragraph in the editor canvas. On trunk it is serif at 16px. With this PR it is the system font at 18px.
  3. In Options → Preferences → Appearance, turn off "Use theme styles". The paragraph keeps the system font.
  4. Activate Twenty Twenty-Five and open the post. Nothing changes from trunk.
Note: See TracTickets for help on using tickets.