Repository navigation
iAPI Router: Reimplement the full-page, client-side navigation feature - #13
Conversation
|
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. |
|
I noticed full-page navigation may fail if an Image block has the lightbox enabled. It's an issue with how Preact reconciles new interactive elements with existing ones, reusing previous hooks values instead of re-initializing them. This patch would solve the issue: diff --git a/packages/block-library/src/image/index.php b/packages/block-library/src/image/index.php
index 697f67a927f..1a3cc65fdd1 100644
--- a/packages/block-library/src/image/index.php
+++ b/packages/block-library/src/image/index.php
@@ -271,6 +271,7 @@ function block_core_image_print_lightbox_overlay() {
echo <<<HTML
<div
class="wp-lightbox-overlay zoom"
+ data-wp-key="wp-lightbox-overlay"
data-wp-interactive="core/image"
data-wp-context='{}'
data-wp-bind--role="state.roleAttribute"
|
|
Size Change: +777 B (+0.04%) Total Size: 1.85 MB
ℹ️ View Unchanged
|
|
There's another issue with the Image block. The lightbox animation is reproduced whenever a page with an Image block with the lightbox enabled is visited. This patch would fix the problem. diff --git a/packages/block-library/src/image/view.js b/packages/block-library/src/image/view.js
index 71a492a570b..3a444a58fea 100644
--- a/packages/block-library/src/image/view.js
+++ b/packages/block-library/src/image/view.js
@@ -130,6 +130,7 @@ const { state, actions, callbacks } = store(
// Resets the current image id to mark the overlay as closed.
state.currentImageId = null;
+ state.showClosingAnimation = false;
}, 450 );
}
},
That part could be revisited, though. Instead of using a timeout, we could add a |
There was a problem hiding this comment.
This is good David, thanks.
I'm happy to see this 🙂
build-module/interactivity-router/index.min.js | 11.2 kB | +10 B (+0.09%)
build-module/interactivity-router/full-page.min.js | 770 B | +770 B (new file)
We need to think about how this is going to be integrated into the a8c plugin and into WooCommerce. Maybe the best option would be to add a filter (like wp_interactivity_experimental_full_page_client_navigation) and have that filter activated by default in the a8c plugin that people are going to use to test it out, but not in Woo.
To follow the same practice as with the private APIs in Gutenberg/Interactivity API, the filter should enable the full-page navigation only when it returns a similar phrase (to be improved):
add_filter( `wp_interactivity_experimental_full_page_client_navigation`, function() {
return 'I acknowledge that full-page client-side navigation is still experimental and will probably change, breaking my plugin or website on its next version.';
});| /** | ||
| * Returns whether the client navigation mode is `experimentalFullPage`. | ||
| */ | ||
| public function is_enabled() { | ||
| $unlock_message = apply_filters( 'wp_interactivity_experimental_full_page_client_navigation', '' ); | ||
| $iapi_router_config = wp_interactivity_config( 'core/router' ); | ||
| return ( | ||
| self::$unlock_message === $unlock_message && | ||
| 'experimentalFullPage' === $iapi_router_config['clientNavigationMode'] ?? '' | ||
| ); | ||
| } |
There was a problem hiding this comment.
I've added the filter to the is_enabled method. I don't know if this is the best approach, though. I would check if there's something similar in WordPress or Gutenberg. 🤔
There was a problem hiding this comment.
The problem is that if someone looks in the config, they will see that clientNavigationMode is still experimentalFullPage.
Perhaps it would be better to move it to set_default_mode and explain people that they have to add the filter in init with a priority of 8?
luisherranz
left a comment
There was a problem hiding this comment.
This looks good to me. I'm approving, although I would change the filter back to wp_footer for security. We don't want people testing this out with old themes reporting that it doesn't work, that could cause them to lose interest 🙂
What?
Note
The previous experimental full-page implementation in Gutenberg was removed at 9756337 in the
interactivity-apibranch. This PR has been created after that.Updates the Interactivity Router logic to support full-page, client-side navigation. This feature shares most of the logic that the region-based navigation feature requires.
Replaces #12.
How?
The event handlers that prefetch and navigate to new pages have been moved to a separate module, importing the main module at request.
The PHP part has been refactored and simplified. Its logic has been moved to a class in 5337993. This change can be reverted if necessary.
Tasks
data-wp-router-regionto the body usingwp_headandwp_footerapproach.navigationModetoclientNavigationMode.initwith priority9.