-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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: Allow global configs for namespaces #58749
Interactivity API: Allow global configs for namespaces #58749
Conversation
@@ -26,9 +31,13 @@ store( 'core/query', { | |||
const queryRef = ref.closest( | |||
'.wp-block-query[data-wp-router-region]' | |||
); | |||
const isDisabled = queryRef?.dataset.wpNavigationDisabled; | |||
const { clientNavigation = true } = getConfig( 'core/router' ); |
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.
I prefer something like clientNavigationDisabled
so we don't have to set a default value when the config is consumed. 😅
Also, maybe this logic should be moved to the Router's navigate
?
cc: @luisherranz
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.
maybe this logic should be moved to the Router's navigate?
Yes, this needs to be done in the router.
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.
There will be some cases where the block needs to know if it's enabled or not, like in an instant search, but the rest of the time it should be automatic.
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.
I prefer something like
clientNavigationDisabled
so we don't have to set a default value when the config is consumed.
I'm not opposed to clientNavigationDisabled
, but can't this be true by default?
const { clientNavigation } = getConfig();
if (clientNavigation !== false) {
// navigate...
}
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 can―it's just that, as a boolean value, it can be confusing why the following code doesn't work:
const { clientNavigation } = getConfig();
if ( clientNavigation ) {
// Oops! It doesn't navigate when undefined, but it should!
}
Anyway, as long as we clarify that an undefined
value should be treated as true
, I'm OK with clientNavigation
.
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.
I also prefer a shorter name, BTW. I'm only worried about potential confusion.
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.
Yep, let's go with clientNavigationDisabled
to avoid confusion.
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.
Changed to clientNavigationDisabled
in 7f60ebe!
Size Change: +4 B (0%) Total Size: 1.71 MB
ℹ️ View Unchanged
|
ee407fe
to
e0876f0
Compare
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. |
61126d2
to
ca35dd7
Compare
Flaky tests detected in eb0ea96. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7835680217
|
7f60ebe
to
75c3074
Compare
75c3074
to
38b60fb
Compare
packages/interactivity/src/store.ts
Outdated
return JSON.parse( storeTag.textContent ); | ||
} catch ( e ) { | ||
// eslint-disable-next-line no-console | ||
console.log( e ); |
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.
Do we want a console.log here?
console.log( e ); | |
return {}; |
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.
I added a comment, as we already have a return at the end of the function. eb0ea96
38b60fb
to
4480404
Compare
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ phpunit/blocks/render-query-test.php |
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.
Looks good to me! 🙂
I've added support for default namespaces in getConfig
in 34289a9. Please, take a look before merging.
What?
Epic: #56803
This PR makes the global config defined with
wp_interactivity_config()
in PHP available in the client, using a new functiongetConfig( namespace )
exposed from@wordpress/interactivity
.Example:
Take in mind that
config
data is not reactive likestate
, i.e., its changes don't trigger any element re-rendering.In this PR, we also remove the
data-wp-navigation-disabled
attribute we were previously including in Query blocks to disable client-side navigations when they contain unsupported blocks. This logic is now handled with theclientNavigation
property inside thecore/router
config data.Why?
Part of #56803.