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: Support setting a namespace using a string in data-wp-interactive #58743

Merged
merged 6 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@

<div data-wp-interactive='{ "namespace": "tovdom-islands" }'>
<div data-wp-show-mock="state.falseValue">
<span data-testid="inside an island">
<span data-testid="inside an island with json object">
This should not be shown because it is inside an island.
</span>
</div>
</div>

<div data-wp-interactive="tovdom-islands">
<div data-wp-show-mock="state.falseValue">
<span data-testid="inside an island with string">
This should not be shown because it is inside an island.
</span>
</div>
Expand Down Expand Up @@ -69,8 +77,6 @@
</div>
</div>



<div data-wp-interactive='{ "namespace": "tovdom-islands" }'>
<div data-wp-interactive='{ "namespace": "something-new" }'></div>
<div data-wp-show-mock="state.falseValue">
Expand Down
1 change: 1 addition & 0 deletions packages/interactivity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Enhancements

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

## 4.0.1 (2024-01-31)

Expand Down
6 changes: 5 additions & 1 deletion packages/interactivity/src/vdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ export function toVdom( root ) {
} catch ( e ) {}
if ( n === islandAttr ) {
island = true;
namespaces.push( value?.namespace ?? null );
namespaces.push(
typeof value === 'string'
? value
: value?.namespace ?? null
);
} else {
directives.push( [ n, ns, value ] );
}
Expand Down
11 changes: 9 additions & 2 deletions test/e2e/specs/interactivity/tovdom-islands.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ test.describe( 'toVdom - islands', () => {
await expect( el ).toBeVisible();
} );

test( 'directives that are inside islands should be hydrated', async ( {
test( 'directives that are inside islands with json objects should be hydrated', async ( {
page,
} ) => {
const el = page.getByTestId( 'inside an island' );
const el = page.getByTestId( 'inside an island with json object' );
await expect( el ).toBeHidden();
} );

test( 'directives that are inside islands with strings should be hydrated', async ( {
page,
} ) => {
const el = page.getByTestId( 'inside an island with string' );
await expect( el ).toBeHidden();
} );

Expand Down
Loading