wp-build: Add configurable script registration priority#75650
wp-build: Add configurable script registration priority#75650dhasilva wants to merge 1 commit intoWordPress:trunkfrom
Conversation
cc3964d to
dca321b
Compare
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Using cc @youknowriad |
dca321b to
ab333e4
Compare
|
For me the solution in this PR is ok but I honestly don't know what's the exact impact here. Like what happens when core gets updated and the plugin is using older "private-apis" than the one used in core... I feel like there's some edge case that we might be missing. |
ab333e4 to
8919c2c
Compare
This is the case on This seems like it needs a separate issue. |
But isn't that a problem, the plugin is going to break other functionality in this case no? |
I think it will, yes. And the private api package is just the most visible problem, the other packages would cause problems as well. But it is hard to test this because core, as I understand, is way behind 🤔 The thing is, it is not related to this PR, it is a pre-existing problem, that is why I think the best approach here is to open a separate issue to find a general solution. |
|
For me it is related to this PR, but just another symptom of it. Personally, I'm starting to think that there's no solution here. In other words, plugins replacing "boot" or "theme" or "private-apis" scripts or modules in Core is a no go. I only see two potential valid solutions: 1- Plugins building using "wp-build" should have a minimal core supported version of 7.0 (where build, theme packages are in Core) 2- Remove the use of "theme" package from "boot" package entirely for now (a bit unfortunate) and each page builds its own "boot" module (so it wouldn't be named "boot" in the output of wp-build) to avoid conflicting with the "boot" package registered by Core/Gutenberg. the latter is ok, but the former is unclear, because if you remove the "theme" package it means there's no clear way for these routes/pages to be "themed" properly according to the WP user profile, usage of @dhasilva how acceptable is option 1 for you, it seems like the "only" safe solution for now :( cc @aduth @jsnajdr I'd appreciate some help, I'm a bit stuck to be honest. (We want to allow third-parties to use |
|
The root cause is somewhere else, and changing the script priority merely covers up the issue instead of solving it. The
These are Core modules and scripts and for some reason the
but instead it builds its own version from the packages installed in
Yes, this sounds like a very natural requirement. The |
Honestly, I don't think it is at all. |
Now I understand that this is an intentional feature added in #73379. If a plugin ships any pages, This polyfilling always overrides the Core/Gutenberg scripts with the plugin version, but that's too naive. First of all, it should be the plugin's responsibility to register the polyfills with a high priority number, so that the registration runs late and can see what others (Core or Gutenberg) have already registered. It should check the already registered versions and override only if it has something newer. One of the polyfills is the If the plugin registered By the way, this also shows a neat way how to circumvent all If Gutenberg started registering its scripts with a higher priority number (causing them to register later), it wouldn't really solve the #75440 bug, because it doesn't deal with scripts registered in Core. What I have WP 7.0 with |
|
I'm not sure how much it helps, but to the point of removing theme usage from boot, the work in #75589 is also working toward the goal of offering backwards-compatibility for versions of WordPress that don't yet have these dependencies. With the issue flagged at Trac#64698, I'm already thinking #75589 and removing reliance on theme tokens being loaded by To the One thought is: If we're talking about trying to fix this in the context of bundling and I also tried thinking about ways we could make private APIs work better across multiple "versions", like additively building up |
|
Closing in favor of #75987 |
What?
Closes #75440
Expands on #75460 by adding a
scriptRegistrationPriorityparameter towpPlugin.Why?
See #75440
Without this, Gutenberg registers scripts with the same priority as the other plugins, which causes a mismatch of the
private-apisversions, crashing the page of the plugin.How?
The configurable
scriptRegistrationPriorityallows Gutenberg to raise its priority above other plugins while other plugins that use wp-build continue with a priority above core's. The default priority is 9, so other plugins do not need to change this value, only Gutenberg needs to raise it.Testing Instructions
1 - Clone https://github.com/dhasilva/minimal-wp-build-test locally
2 - Uncomment these lines to avoid an unrelated problem
4 -
pnpm installand build the test plugin withpnpm run build5 - Go to Tools > Minimal WP-Build Test
6 - Check that you see the error in the linked issue
7 - Symlink wp-build to the plugin's dependencies:
8 - Rebuild the test plugin:
pnpm run build9 - Check
/build/scripts.php, it should register scripts with priority 9:add_action( 'wp_default_scripts', 'minimal_wp_build_test_register_package_scripts', 9 );10 - Rebuild Gutenberg
11 - Check Gutenbergs' /build/scripts.php, it should have priority 10
12 - Go to Tools > Minimal WP-Build Test again
13 - Check that the page loads
Testing Instructions for Keyboard
Screenshots or screencast