Skip to content

Commit cda700c

Browse files
luisherranzDAreRodz
andauthored
Interactivity API: Support setting a namespace using a string in data-wp-interactive (#58743)
* Add failing test * Fix the test * Add changelog (without PR number) * Remove comment about namespace restrictions * Revert namespace char restriction * Update PR number in CHANGELOG.md Co-authored-by: luisherranz <luisherranz@git.wordpress.org> Co-authored-by: DAreRodz <darerodz@git.wordpress.org>
1 parent 9edf886 commit cda700c

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

packages/e2e-tests/plugins/interactive-blocks/tovdom-islands/render.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@
1717

1818
<div data-wp-interactive='{ "namespace": "tovdom-islands" }'>
1919
<div data-wp-show-mock="state.falseValue">
20-
<span data-testid="inside an island">
20+
<span data-testid="inside an island with json object">
21+
This should not be shown because it is inside an island.
22+
</span>
23+
</div>
24+
</div>
25+
26+
<div data-wp-interactive="tovdom-islands">
27+
<div data-wp-show-mock="state.falseValue">
28+
<span data-testid="inside an island with string">
2129
This should not be shown because it is inside an island.
2230
</span>
2331
</div>
@@ -69,8 +77,6 @@
6977
</div>
7078
</div>
7179

72-
73-
7480
<div data-wp-interactive='{ "namespace": "tovdom-islands" }'>
7581
<div data-wp-interactive='{ "namespace": "something-new" }'></div>
7682
<div data-wp-show-mock="state.falseValue">

packages/interactivity/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Enhancements
66

77
- Break up init with yielding to main to prevent long task from hydration. ([#58227](https://github.com/WordPress/gutenberg/pull/58227))
8+
- Support setting the namespace using a string in `data-wp-interactive`, like `data-wp-interactive="myPlugin"`. ([#58743](https://github.com/WordPress/gutenberg/pull/58743))
89

910
## 4.0.1 (2024-01-31)
1011

packages/interactivity/src/vdom.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ export function toVdom( root ) {
8585
} catch ( e ) {}
8686
if ( n === islandAttr ) {
8787
island = true;
88-
namespaces.push( value?.namespace ?? null );
88+
namespaces.push(
89+
typeof value === 'string'
90+
? value
91+
: value?.namespace ?? null
92+
);
8993
} else {
9094
directives.push( [ n, ns, value ] );
9195
}

test/e2e/specs/interactivity/tovdom-islands.spec.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,17 @@ test.describe( 'toVdom - islands', () => {
2323
await expect( el ).toBeVisible();
2424
} );
2525

26-
test( 'directives that are inside islands should be hydrated', async ( {
26+
test( 'directives that are inside islands with json objects should be hydrated', async ( {
2727
page,
2828
} ) => {
29-
const el = page.getByTestId( 'inside an island' );
29+
const el = page.getByTestId( 'inside an island with json object' );
30+
await expect( el ).toBeHidden();
31+
} );
32+
33+
test( 'directives that are inside islands with strings should be hydrated', async ( {
34+
page,
35+
} ) => {
36+
const el = page.getByTestId( 'inside an island with string' );
3037
await expect( el ).toBeHidden();
3138
} );
3239

0 commit comments

Comments
 (0)