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: Update iterable signals when deepMerge() adds new properties #65135

Merged
merged 4 commits into from
Sep 9, 2024

Conversation

DAreRodz
Copy link
Contributor

@DAreRodz DAreRodz commented Sep 7, 2024

What?

Fixes deepMerge() to update the corresponding internal signals for property iteration (i.e., ...obj, Object.keys( obj ), Reflect.ownKeys( obj ), etc.

Why?

When a deepMerge() call adds new properties to an object, the corresponding iterable signal should be updated to ensure subscribed directives react to changes.

How?

Modifying the corresponding signal for the target object when necessary.

Testing Instructions

A unit test was added that didn't pass before the bug fix.

@DAreRodz DAreRodz added [Type] Bug An existing feature does not function as intended [Feature] Interactivity API API to add frontend interactivity to blocks. [Packages] Interactivity /packages/interactivity labels Sep 7, 2024
@DAreRodz DAreRodz self-assigned this Sep 7, 2024
@DAreRodz DAreRodz marked this pull request as ready for review September 7, 2024 18:00
Copy link

github-actions bot commented Sep 7, 2024

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: DAreRodz <[email protected]>
Co-authored-by: michalczaplinski <[email protected]>
Co-authored-by: cbravobernal <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

github-actions bot commented Sep 7, 2024

Flaky tests detected in 7b7e0cf.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/10753358050
📝 Reported issues:

Copy link
Contributor

@michalczaplinski michalczaplinski left a 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! The change makes sense and has a passing test 👍

@@ -277,12 +277,13 @@ const deepMergeRecursive = (
) => {
if ( isPlainObject( target ) && isPlainObject( source ) ) {
for ( const key in source ) {
const isNew = ! ( key in target );
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe "hasNewData" or "hasNewProperties" defines better the issue.

Copy link
Contributor Author

@DAreRodz DAreRodz Sep 9, 2024

Choose a reason for hiding this comment

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

Here, isNew refers to the current key inside the loop. But that's a good point anyway; we could move the signal update outside the loop. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in d516c42.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Interactivity API API to add frontend interactivity to blocks. [Packages] Interactivity /packages/interactivity [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants