-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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: Correctly handle lazily added, deeply nested properties with deepMerge()
#65465
Conversation
// The effect should be called again | ||
expect( spy ).toHaveBeenCalledTimes( 2 ); | ||
expect( deepValue ).toBe( 'test value' ); |
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.
@DAreRodz both of those assertions fail:
-
expect( spy ).toHaveBeenCalledTimes( 2 );
Expected number of calls: 2 Received number of calls: 1
-
expect( deepValue ).toBe( 'test value' );
Expected: "test value" Received: undefined
But I'm not 100% sure if those are precisely the failures we wanted to see.
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.
Thanks for the PR, @michalczaplinski. 😁
I'm not 100% sure if those are precisely the failures we wanted to see.
They are. The values received are the same as those returned in the initial call. Basically, the spy
function has not been executed again because the signal for context.a
has not been updated.
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 had to stare at the test a little longer to convince myself that it was actually the case 😅.
Excellent, I'll add the fix tomorrow 🙂
As we discussed, I was expecting the unit test to fail, but after updating the test cases they are actually passing! Here's what's going on. Let's assume I'm going through an example that follows the newly added unit tests in this PR - meaning I'm trying to follow what's going on when running the following code: const fallback: any = proxifyContext(
proxifyState( 'test', {} ),
{}
);
const context: any = proxifyContext(
proxifyState( 'test', {} ),
fallback
);
deepMerge( context, { a: { b: { c: { d: 'test value' } } } } ); When we set a property on the context using gutenberg/packages/interactivity/src/proxies/state.ts Lines 303 to 305 in 3ef1f89
This triggers the
At this point:
Since the gutenberg/packages/interactivity/src/proxies/state.ts Lines 165 to 166 in 3ef1f89
However, the gutenberg/packages/interactivity/src/proxies/state.ts Lines 175 to 177 in 3ef1f89
After that, gutenberg/packages/interactivity/src/proxies/state.ts Lines 307 to 308 in 3ef1f89
As we call |
Oh, I understand now. 😄 The context currently uses two proxies: one for property inheritance ( This is what we do in the
In 48433fe, I moved one of the tests to
|
Flaky tests detected in 8f7fc13. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11013548741
|
48433fe
to
8f7fc13
Compare
deepMerge()
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. |
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 just added the changelog changes. The rest looks good to me.
Add a test to ensure the context proxy correctly handles and updates deeply nested properties that are initially undefined.
2a9bc08
to
005f42d
Compare
There was a conflict while trying to cherry-pick the commit to the wp/6.7 branch. Please resolve the conflict manually and create a PR to the wp/6.7 branch. PRs to wp/6.7 are similar to PRs to trunk, but you should base your PR on the wp/6.7 branch instead of trunk.
|
There was a conflict while trying to cherry-pick the commit to the wp/6.7 branch. Please resolve the conflict manually and create a PR to the wp/6.7 branch. PRs to wp/6.7 are similar to PRs to trunk, but you should base your PR on the wp/6.7 branch instead of trunk.
|
…rties with `deepMerge()` (#65465) * test: Add case for deeply nested undefined properties in context proxy Add a test to ensure the context proxy correctly handles and updates deeply nested properties that are initially undefined. * Update the test case to use `proxifyState()` * Add test for deepMerge with nested undefined properties * Add a failing test in `deep-merge.ts` * Add another failing test * Make all the tests pass * Simplify code * Fix test case name * Add one extra test * Update test in `context-proxy` * Update changelog --------- Co-authored-by: michalczaplinski <[email protected]> Co-authored-by: DAreRodz <[email protected]> Co-authored-by: cbravobernal <[email protected]>
…rties with `deepMerge()` (#65465) * test: Add case for deeply nested undefined properties in context proxy Add a test to ensure the context proxy correctly handles and updates deeply nested properties that are initially undefined. * Update the test case to use `proxifyState()` * Add test for deepMerge with nested undefined properties * Add a failing test in `deep-merge.ts` * Add another failing test * Make all the tests pass * Simplify code * Fix test case name * Add one extra test * Update test in `context-proxy` * Update changelog --------- Co-authored-by: michalczaplinski <[email protected]> Co-authored-by: DAreRodz <[email protected]> Co-authored-by: cbravobernal <[email protected]>
I just cherry-picked this PR to the release/19.4 branch to get it included in the next release: dc70023 |
…rties with `deepMerge()` (WordPress#65465) * test: Add case for deeply nested undefined properties in context proxy Add a test to ensure the context proxy correctly handles and updates deeply nested properties that are initially undefined. * Update the test case to use `proxifyState()` * Add test for deepMerge with nested undefined properties * Add a failing test in `deep-merge.ts` * Add another failing test * Make all the tests pass * Simplify code * Fix test case name * Add one extra test * Update test in `context-proxy` * Update changelog --------- Co-authored-by: michalczaplinski <[email protected]> Co-authored-by: DAreRodz <[email protected]> Co-authored-by: cbravobernal <[email protected]>
Description
This PR addresses an issue in the Interactivity API where deeply nested properties that are initially undefined and later added with the inter
deepMerge()
to either the context or the global state were not being properly handled. The change ensures that effects dependent on these properties are correctly triggered when the properties are added, even if they are initially undefined.Changes
packages/interactivity/src/proxies/test/context-proxy.ts
to demonstrate the desired behavior for deeply nested properties.deepMerge
function to support this behavior.Testing
A new test case has been added to verify the correct handling of deeply nested properties.