-
Notifications
You must be signed in to change notification settings - Fork 11
Limit the hydration to block when client-side navigations are deactivated #124
Conversation
It's still not working, at least in my local environment, but at least I didn't change it.
Thanks for opening the Pull Request! Something I was wondering about: Would it make sense, and would it be possible, to automatically detect if a block is using directives and add the Btw, it could be something to do in the future and it may be out of the scope of this PR. |
Yes, it would be possible 🙂 What is not possible is to differentiate between an "isolated" and a "parent" block. But maybe we could do the opposite and treat every interactive block as a parent block unless it specifies that it is isolated? That way it'd be safer to automatically detect the directives. |
I've just watched again the video you shared in the issue, and you mentioned it. I knew I had heard the idea somewhere 😄
Maybe not every interactive block but the ones including directives that could imply it needs inter-block communication like |
Yeah, good point. That would require declaring it somehow on the directive declaration, but directive declarations will be used way less often so we can push that complexity there 🙂
True! Let's do that then, but in a subsequent PR. |
This should be ready for review. https://www.loom.com/share/78003554808d492b819794170e95f38a Some notes:
|
By the way, once this is merged, I want to add it to #103 to compare the
|
I started taking a look at the PR. It looks great! I have a couple of comments so far:
<p>Isolated block</p>
<div><wp-show when="state.dontShow">hide me</wp-show></div>
|
Yes, the requirement for blocks to have a single wrapper node extends to inner blocks as well. Maybe the Custom HTML block should have a default wrapper: But maybe something can be done with the new capabilities of the
Wonderful. Thanks for checking it out, Mario! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the requirement for blocks to have a single wrapper node extends to inner blocks as well. Maybe the Custom HTML block should have a default wrapper.
Okay, I didn't remember that part. Then everything looks great to me 🙂 Although it would be great if someone else can double check the code.
function wp_directives_get_client_side_transitions() { | ||
static $client_side_transitions = null; | ||
if ( is_null( $client_side_transitions ) ) { | ||
$client_side_transitions = apply_filters( 'client_side_transitions', false ); | ||
} | ||
return $client_side_transitions; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we here just call the function that gets the options instead of creating a new filter? get_option()
by default uses filter and return false in case it does not exist.
Something like
$directive_plugins_settings = get_option('wp_directives_plugin_settings');
is_array($directive_plugins_settings) return $directive_plugins_settings['client_side_transitions'];
return $false;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's very unlikely that we will start storing that option in a plugin's setting. It will likely be an experimental feature that will need to be turned on using the filter, so I'd rather keep it as it is 🙂
Merging now so we can continue. If there's something broken, we'll fix it later 🙂 |
Btw, should we open a new issue to automate this with the HTML_Tag_Processor? Or is there a better place to keep track of that? |
What
This PR will limit the hydration so it only happens in the interactive blocks.
Fixes #93.
Why
To avoid the cost of the Directives Hydration when it's strictly not necessary. Full explanation in #93.
How
It keeps using the same
meta
tag mechanism to know if client-side navigations are enabled or not. If they are not, instead of doing the Directives Hydration, it looks for the interactive blocks and hydrates only those. Interactive blocks opt-in using asupports.interactivity
property in theirblock.json
and they are marked with awp-island
attribute in the HTML.Tasks
wp-island
attribute to blocks withsupports.interactivity
wp-island
attributewp-ignore
attributewp-ignore
nodesprettier-php
tophpcs
)wp-island
andwp-ignore
when client-side navigations are enabledDon't stop inwp-ignore
when client-side navigations are enabledAdditional comments
deepsignal
code, which was broken in the main branch.