Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactivity API: Create @wordpress/interactivity-router module #57924

Merged
merged 55 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
270aaa0
Copy the wp-each implementation
DAreRodz Jan 15, 2024
09972e6
Scaffold files for wp-each e2e tests
DAreRodz Jan 15, 2024
926da69
Process template nodes inside `toVdom()`
DAreRodz Jan 15, 2024
7f2f6c3
Add tests for several list manipulations
DAreRodz Jan 15, 2024
63fa0ef
Add a new test to implement
DAreRodz Jan 15, 2024
5019c6e
Add SSRed elements in PHP
DAreRodz Jan 15, 2024
7819728
Add SSRed elements to letters test
DAreRodz Jan 15, 2024
9308769
Add more test cases
DAreRodz Jan 15, 2024
13be90d
Test support for siblings in template
DAreRodz Jan 15, 2024
e90ddfc
Implement tests for wp-each on navigation
DAreRodz Jan 16, 2024
4643f4b
Update changelog
DAreRodz Jan 16, 2024
07a53b6
Add `wp-each` documentation
DAreRodz Jan 16, 2024
d6b0a4e
Separate the router from the rest of the runtime
DAreRodz Jan 17, 2024
fc423df
Import deps from interactivity module
DAreRodz Jan 17, 2024
77bd06a
Add an entry point for the router
DAreRodz Jan 17, 2024
b3b3ebb
Register interactivity router module
DAreRodz Jan 17, 2024
e38ff22
Add the router module to query block dependencies
DAreRodz Jan 17, 2024
227aa86
Cache regions on DOMContentLoaded
DAreRodz Jan 17, 2024
adf8203
Update query block view
DAreRodz Jan 17, 2024
144c15c
Update e2e tests
DAreRodz Jan 17, 2024
f3a01ee
Make router module a dynamic dependency in tests
DAreRodz Jan 19, 2024
6d245b3
Update tests using navigate
DAreRodz Jan 19, 2024
82a9d4a
Expose `state` & `actions` from router module
DAreRodz Jan 22, 2024
cbf4d3e
Fix module dependency definition for tests
DAreRodz Jan 22, 2024
dd7131e
Fix php lint
DAreRodz Jan 22, 2024
2e5d7e7
Refactor dynamic imports in tests
DAreRodz Jan 22, 2024
8b517b8
Attempt to fix webpack config
DAreRodz Jan 22, 2024
44d2a37
Update caniuse-lite package
sirreal Jan 22, 2024
ffdbdc9
Update snapshots
sirreal Jan 22, 2024
0bf64e3
Cleanup DEWP name, ensure no dupe plugin
sirreal Jan 22, 2024
5c1554f
fixup! Cleanup DEWP name, ensure no dupe plugin
sirreal Jan 22, 2024
93a7ea6
fixup! fixup! Cleanup DEWP name, ensure no dupe plugin
sirreal Jan 22, 2024
94dfd8c
Merge branch 'trunk' into try/interactivity-api-router-module
DAreRodz Jan 23, 2024
f752a94
Convert `navigate` and `prefetch` into actions
DAreRodz Jan 23, 2024
5d55caa
Do not use generator for `prefetch`
DAreRodz Jan 23, 2024
7999837
Add changelog entry
DAreRodz Jan 23, 2024
7b9e112
Create @wordpress/interactivity-router package
DAreRodz Jan 24, 2024
d09960e
Update package-lock
DAreRodz Jan 24, 2024
9916bea
Add the new package to the DEWP
luisherranz Jan 24, 2024
1e6b1c5
Use module as the externals default in the experimental module suppor…
luisherranz Jan 24, 2024
3e50a84
Revert "Update package-lock"
DAreRodz Jan 24, 2024
e551609
Revert "Create @wordpress/interactivity-router package"
DAreRodz Jan 24, 2024
e1bf002
Remove unnecessary DEWP
DAreRodz Jan 24, 2024
19185a3
Merge branch 'trunk' into try/interactivity-api-router-module
luisherranz Jan 24, 2024
4e9d82a
Refactor for new Script Modules API
luisherranz Jan 24, 2024
f42d597
Fix router module name inside DEWP
DAreRodz Jan 24, 2024
f7596c2
Add DEWP to plugins
DAreRodz Jan 24, 2024
337d22a
Revert "Revert "Create @wordpress/interactivity-router package""
DAreRodz Jan 24, 2024
4dcfe20
Revert "Revert "Update package-lock""
DAreRodz Jan 24, 2024
2534189
Update interactivity-router after reverts
DAreRodz Jan 24, 2024
87e162d
Fix module dependencies in Query block
DAreRodz Jan 24, 2024
1aaf239
Add changelog entry
DAreRodz Jan 24, 2024
c15686c
Fix typo
luisherranz Jan 24, 2024
d196e04
Revert adding externalsType in wp-scripts
luisherranz Jan 24, 2024
980ad9b
Merge remote-tracking branch 'origin/try/interactivity-api-router-mod…
luisherranz Jan 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 14 additions & 6 deletions packages/dependency-extraction-webpack-plugin/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ function defaultRequestToExternal( request ) {
/**
* Default request to external module transformation
*
* Currently only @wordpress/interactivity
* Currently only @wordpress/interactivity and `@wordpress/interactivity-router`
* are supported.
*
* Do not use the boolean shorthand here, it's only handled for the `requestToExternalModule` option.
* Do not use the boolean shorthand here, it's only handled for the
* `requestToExternalModule` option.
*
* @param {string} request Module request (the module name in `import from`) to be transformed
* @return {string|Error|undefined} The resulting external definition.
Expand All @@ -71,13 +73,19 @@ function defaultRequestToExternal( request ) {
*/
function defaultRequestToExternalModule( request ) {
if ( request === '@wordpress/interactivity' ) {
// This is a special case. Interactivity does not support dynamic imports at this
// time. We add the external "module" type to indicate that webpack should
// externalize this as a module (instead of our default `import()` external type)
// which forces @wordpress/interactivity imports to be hoisted to static imports.
// This is a special case. Interactivity does not support dynamic imports at
// this time. We add the external "module" type to indicate that webpack
// should externalize this as a module (instead of our default `import()`
// external type) which forces @wordpress/interactivity imports to be
// hoisted to static imports.
return `module ${ request }`;
}

if ( request === '@wordpress/interactivity-router' ) {
// Assumes this is usually giong to be used as a dynamic import.
luisherranz marked this conversation as resolved.
Show resolved Hide resolved
return `import ${ request }`;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the kind of change that I'd like us to improve as part of adding these new modules, we should be adding hacks like this when we create new packages/modules. Instead we should have everything taken care of automatically. How can we do that here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, all the WordPress packages should be available as modules. Once that's done, we can update this to do something similar to what's done for scripts and make any module that starts with @wordpress external.


const isWordPressScript = Boolean( defaultRequestToExternal( request ) );

if ( isWordPressScript ) {
Expand Down
2 changes: 2 additions & 0 deletions packages/scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ if ( hasExperimentalModulesFlag ) {
},
},

externalsType: 'module',

plugins: [
new webpack.DefinePlugin( {
// Inject the `SCRIPT_DEBUG` global, used for development features flagging.
Expand Down