Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/wp-build/templates/module-registration.php.template
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ function {{PREFIX}}_register_script_modules() {
$asset = file_exists( $asset_path ) ? require $asset_path : array();

// Deregister first to override any previously registered version
// (e.g., Core's default modules when running as a plugin).
wp_deregister_script_module( $module['id'] );
// of Core's default script modules. Scoped to `@wordpress/*` — the
// only namespace Core registers by default — so plugin-local and
// shared packages preserve Core's idempotent "first-wins" semantics.
if ( str_starts_with( $module['id'], '@wordpress/' ) ) {
wp_deregister_script_module( $module['id'] );
}

wp_register_script_module(
$module['id'],
Expand Down
14 changes: 10 additions & 4 deletions packages/wp-build/templates/routes-registration.php.template
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ function {{PREFIX}}_register_page_routes( $page_routes, $register_function_name
$content_handle = '{{HANDLE_PREFIX}}/routes/' . $route['name'] . '/content';
$extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
// Deregister first to override any previously registered version
// (e.g., Core's default modules when running as a plugin).
wp_deregister_script_module( $content_handle );
// of Core's default script modules. Scoped to `@wordpress/*` — the
// only namespace Core registers by default.
if ( str_starts_with( $content_handle, '@wordpress/' ) ) {
wp_deregister_script_module( $content_handle );
}
wp_register_script_module(
$content_handle,
$build_constants['build_url'] . 'routes/' . $route['name'] . '/content' . $extension,
Expand All @@ -73,8 +76,11 @@ function {{PREFIX}}_register_page_routes( $page_routes, $register_function_name
$route_handle = '{{HANDLE_PREFIX}}/routes/' . $route['name'] . '/route';
$extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
// Deregister first to override any previously registered version
// (e.g., Core's default modules when running as a plugin).
wp_deregister_script_module( $route_handle );
// of Core's default script modules. Scoped to `@wordpress/*` — the
// only namespace Core registers by default.
if ( str_starts_with( $route_handle, '@wordpress/' ) ) {
wp_deregister_script_module( $route_handle );
}
wp_register_script_module(
$route_handle,
$build_constants['build_url'] . 'routes/' . $route['name'] . '/route' . $extension,
Expand Down
Loading