Make WordPress Core

Opened 13 months ago

Closed 13 months ago

Last modified 12 months ago

#58648 closed defect (bug) (fixed)

Error: tinymce is not defined in post-new.php

Reported by: joemcgill's profile joemcgill Owned by: joemcgill's profile joemcgill
Milestone: 6.3 Priority: normal
Severity: normal Version: 6.3
Component: Script Loader Keywords: has-patch has-unit-tests
Focuses: performance Cc:

Description

The E2E tests began showing a tinymce is not defined error, which can be replicated in trunk by visiting the post edit screen and checking the developer console.

After some debugging, this looks like it's due to an inline script that is printed after the tinymce scripts in print_tinymce_scripts(). For some reason, this function is causing the tinymce scripts to be printed with an async loading strategy, which result in the inline script being loaded before the tinymce scripts have loaded. This is likely related to [56033].

Change History (17)

This ticket was mentioned in PR #4731 on WordPress/wordpress-develop by joemcgill.


13 months ago
#1

  • Keywords has-patch has-unit-tests added; needs-patch removed

#2 @joemcgill
13 months ago

I've opened a PR that demonstrates the broken behavior in order to help with debugging.

#3 @joemcgill
13 months ago

Figured out what was happening here. print_tinymce_scripts() calls wp_print_scripts() to directly print the tinymce scripts without enqueueing them. When deciding which loading strategy to apply to a script in WP_Scripts::get_eligible_loading_strategy(), start with all possible strategies and then filter down to the one that should be applied in WP_Scripts::filter_eligible_strategies(). However, that method intentionally skips evaluating any handles that aren't enqueued to avoid situations where a script's eligible strategy would be affected by a dependent that was not enqueued.

I've updated the PR so that before we start the filtering process, we first take into account the intended strategy of the handle when it is registered.

#4 @peterwilsoncc
13 months ago

#58652 was marked as a duplicate.

This ticket was mentioned in Slack in #core by ocean90. View the logs.


13 months ago

#6 @azaozz
13 months ago

In 56092:

Script Loader: Fix unintended adding of async to scripts that are printed directly with wp_print_scripts() without enqueueing them beforehand.

Props: joemcgill, westonruter, felixarntz, peterwilsoncc.
See: #58648.

#7 follow-up: @azaozz
13 months ago

Leaving the ticket open as there are few (non-blocking) suggestions on the PR that may be added later.

@Bernhard Reiter commented on PR #4731:


13 months ago
#8

Bit of a long shot, but I think @tyxla recently worked on TinyMCE. Marin, is this code something you're familiar with? If so, could you weigh in here? 😊

@tyxla commented on PR #4731:


13 months ago
#9

Bit of a long shot, but I think @tyxla recently worked on TinyMCE. Marin, is this code something you're familiar with? If so, could you weigh in here? 😊

Thanks for the ping!

From what I can see this isn't related to my experimentation on the Gutenberg side; it's rather related to the recent introduction of the async and defer loading strategy in https://core.trac.wordpress.org/ticket/12009.

The proposed fix appears to be spot on 👍

@azaozz commented on PR #4731:


13 months ago
#10

Right, the bug was that async was added to scripts that were "printed" directly without being enqueues first. The fix works well and was committed in https://core.trac.wordpress.org/changeset/56092.

Not closing this PR as there are few suggestions that can be added later.

This ticket was mentioned in Slack in #core by chaion07. View the logs.


13 months ago

This ticket was mentioned in Slack in #core by oglekler. View the logs.


13 months ago

#13 in reply to: ↑ 7 @azaozz
13 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

Replying to azaozz:

Leaving the ticket open as...

Lets close this for 6.3. Any suggested changes can be added later if they're worth it.

This ticket was mentioned in PR #4852 on WordPress/wordpress-develop by joemcgill.


13 months ago
#14

This applies a couple of suggestions from #4731 that were not resolved before the initial commit.

Trac ticket: https://core.trac.wordpress.org/ticket/58648

joemcgill commented on PR #4731:


13 months ago
#15

Moved followup tasks to a different PR to clarify what would be committed separately.

#16 @joemcgill
12 months ago

In 56246:

Script Loader: Improve test coverage for wp_print_scripts().

This is a follow-up to [56092], which further improves PHPUnit test coverage and inline docs for ensuring async and defer attributes are being properly handled for scripts that are printed without being enqueued.

Props peterwilsoncc, azaozz, westonruter, joemcgill.
See #58648.

Note: See TracTickets for help on using tickets.