Interactivity API: Remove non default suffix data wp context processing.#58664
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 Core SVNCore Committers: Use this line as a base for the props when committing in SVN: GitHub Merge commitsIf 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. |
|
Size Change: -14 B (0%) Total Size: 1.69 MB
ℹ️ View Unchanged
|
DAreRodz
left a comment
There was a problem hiding this comment.
I left some suggestions, @c4rl0sbr4v0!
packages/e2e-tests/plugins/interactive-blocks/directive-context/render.php
Show resolved
Hide resolved
| // If there's an error, we'll just return the inherited context. | ||
| return ( | ||
| <Provider value={ inheritedValue }>{ children }</Provider> | ||
| ); |
There was a problem hiding this comment.
We don't need to render another Provider as the inherited value already comes from a Provider. Actually, we can skip this part entirely because the directives don't need to return anything. 🤓
There was a problem hiding this comment.
An empty return is enough.
| currentValue.current = useMemo( () => { | ||
| const newValue = deepSignal( { | ||
| [ namespace ]: value, | ||
| } ); | ||
| mergeDeepSignals( newValue, inheritedValue ); | ||
| mergeDeepSignals( currentValue.current, newValue, true ); | ||
| return currentValue.current; | ||
| }, [ inheritedValue, ...passedValues ] ); |
There was a problem hiding this comment.
I don't expect useMemo() to throw an error. Moving this outside of the try { ... } catch would be better.
There was a problem hiding this comment.
However, if this is intentional, then we need to include a test for that case, don't we? 🤔
There was a problem hiding this comment.
I added previously cause there was errors of trying to map an undefined variable.
As we are now removing:
.map( ( c ) => deepSignal( { [ c.namespace ]: c.value } ) )
.reduceRight( mergeDeepSignals );
That possible error has gone. Now it works fine with two contexts. As you mentioned to add to the test.
Thank you very much! 🙇♂️ |
|
Flaky tests detected in b68c44c. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7787693813
|
What?
Prevent from processing directives of
data-wp-contextwith other suffixes. In other directives, you may have different suffixes like:data-wp-on-document-readyordata-wp-on-document-scrollBut, in
data-wp-context, we only want developers to usedata-wp-context, notdata-wp-context--aordata-wp-context--bWhy?
Because there is no need to overcomplicate things. Contexts are unique per element, and you can always add more elements to the already existing context rather than creting new ones.
Testing Instructions
data-wp-context-whatever.wp-textdirective reading that context.