Skip to content

Commit 62d1311

Browse files
committed
fix: Ensure hook registration occurs in global wp.hooks namespace
Localizing the `@wordpress/hook` package meant two namespaces existed: 1. The localized module bundled by Vite; 2. And the `wp.hooks` global provided by the remote site scripts. Hooks registered by GutenbergKit used the former, but the latter is the namespace utilized by the running editor. Therefore, the hooks were never applied. The localization of `@wordpress/hooks` was originally done in service of our top-level usage of the `@wordpress/api-fetch` module for fetching remote assets. Localizing dependencies like this may be misguided and have no impact on the outcome at all, as Vite configuration does not impact `node_modules`, only GutenbergKit source. Additionally, we likely have opportunity to refactor and remove our localization of the `@wordpress/api-fetch` module entirely. We now fetch editor assets via the native code. We no longer needs to load the `apiFetch` utility before the remote sites scripts are loaded.
1 parent 87f53cc commit 62d1311

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

vite.config.remote.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function externalize( id ) {
3838
return (
3939
!! externalDefinition &&
4040
! id.match( /\.css(?:\?inline)?$/ ) &&
41-
! [ 'apiFetch', 'i18n', 'url', 'hooks' ].includes(
41+
! [ 'apiFetch', 'i18n', 'url' ].includes(
4242
externalDefinition[ externalDefinition.length - 1 ]
4343
)
4444
);
@@ -67,8 +67,8 @@ function wordPressExternals() {
6767

6868
if (
6969
! externalDefinition ||
70-
/@wordpress\/(api-fetch|url|hooks)/.test( id ) ||
71-
/@wordpress\/(api-fetch|url|hooks)/.test( module )
70+
/@wordpress\/(api-fetch|url)/.test( id ) ||
71+
/@wordpress\/(api-fetch|url)/.test( module )
7272
) {
7373
continue; // Exclude the module from externalization
7474
}

0 commit comments

Comments
 (0)