-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Interactivity API: Only add proxies to plain objects inside the store (…
…#59039) * Only proxify plain objects * Do not support objects without prototypes * Rename store-tag to interactivity-data * Add test for non-plain objects in state * Update `isObject` implementation * Update changelog --------- Co-authored-by: c4rl0sbr4v0 <cbravobernal@git.wordpress.org> Co-authored-by: DAreRodz <darerodz@git.wordpress.org>
- Loading branch information
1 parent
d79c286
commit 55b032f
Showing
7 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
packages/e2e-tests/plugins/interactive-blocks/store/block.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "test/store", | ||
"title": "E2E Interactivity tests - store definition", | ||
"category": "text", | ||
"icon": "heart", | ||
"description": "", | ||
"supports": { | ||
"interactivity": true | ||
}, | ||
"textdomain": "e2e-interactivity", | ||
"viewScript": "store-view", | ||
"render": "file:./render.php" | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/e2e-tests/plugins/interactive-blocks/store/render.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
/** | ||
* HTML for testing the directive `data-wp-bind`. | ||
* | ||
* @package gutenberg-test-interactive-blocks | ||
*/ | ||
|
||
wp_enqueue_script_module( 'store-view' ); | ||
?> | ||
|
||
<div data-wp-interactive="test/store"> | ||
<div | ||
data-testid="non-plain object" | ||
data-wp-text="state.isNotProxified" | ||
data-wp-init="callbacks.init" | ||
></div> | ||
</div> |
20 changes: 20 additions & 0 deletions
20
packages/e2e-tests/plugins/interactive-blocks/store/view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { store, getElement } from '@wordpress/interactivity'; | ||
|
||
|
||
const { state } = store( 'test/store', { | ||
state: { | ||
get isNotProxified() { | ||
const { ref } = getElement(); | ||
return state.elementRef === ref; | ||
} | ||
}, | ||
callbacks: { | ||
init() { | ||
const { ref } = getElement(); | ||
state.elementRef = ref; // HTMLElement | ||
} | ||
} | ||
} ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { test, expect } from './fixtures'; | ||
|
||
test.describe( 'data-wp-bind', () => { | ||
test.beforeAll( async ( { interactivityUtils: utils } ) => { | ||
await utils.activatePlugins(); | ||
await utils.addPostWithBlock( 'test/store' ); | ||
} ); | ||
|
||
test.beforeEach( async ( { interactivityUtils: utils, page } ) => { | ||
await page.goto( utils.getLink( 'test/store' ) ); | ||
} ); | ||
|
||
test.afterAll( async ( { interactivityUtils: utils } ) => { | ||
await utils.deactivatePlugins(); | ||
await utils.deleteAllPosts(); | ||
} ); | ||
|
||
test( 'non-plain objects are not proxified', async ( { page } ) => { | ||
const el = page.getByTestId( 'non-plain object' ); | ||
await expect( el ).toHaveText( 'true' ); | ||
} ); | ||
} ); |
55b032f
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.
Flaky tests detected in 55b032f.
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/7979057621
📝 Reported issues:
/test/e2e/specs/editor/blocks/navigation.spec.js