Skip to content

Commit 14763bd

Browse files
Interactivity API: Remove expired deprecated behaviors (#84098)
* Interactivity API: Migrate Interactivity fixtures to supported directive forms * Interactivity API: Use full event suffix in event directives * Interactivity API: Skip suffixed lifecycle directives * Interactivity API: Do not invoke negated functions * Interactivity API: Remove special handling for data-wp-ignore * Interactivity API: Update island hydration e2e coverage * Interactivity API: Correct hydration fixture explanation * Interactivity API: Remove expired unique-ID deprecation notices from Interactivity API reference * Interactivity API: Announce removals in the changelog * Interactivity API: Normalize reference emphasis formatting * Interactivity API: Reference removal PR in the changelog * Interactivity API: Warn about two-hyphen event names Event directives now read the whole suffix as the event name, so a leftover two-hyphen unique ID silently listens for an event that never fires. Warn in development mode and suggest the three-hyphen form. Document that the deprecated async event directives still cut the event name at `--`. * Interactivity API: Share the unsupported suffix warning with router-region Align the warnSuffixNotSupported() wording with the existing router-region message and use the helper there too. * Interactivity API: Warn about leftover data-wp-ignore attributes * Interactivity API: Remove JSDoc from the Evaluate interface * Interactivity API: Move and extend tests for removed deprecations Move the tests next to the other directive tests and follow their conventions. Cover production mode, the new warnings, data-wp-ignore hydration, deprecated async event directives, and negation of values and getters. * Interactivity API: Rename stale isolated island e2e fixtures * Interactivity API: Document unique IDs for event directives and function negation * Interactivity API: Split the breaking changes changelog entry --------- Co-authored-by: David <david.arenas@automattic.com> Co-authored-by: luisherranz <luisherranz@git.wordpress.org>
1 parent 6906205 commit 14763bd

23 files changed

Lines changed: 427 additions & 151 deletions

File tree

‎docs/reference-guides/interactivity-api/directives-and-store.md‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,17 @@ The `wp-on` directive is executed each time the associated event is triggered.
415415

416416
The callback passed as the reference receives [the event](https://developer.mozilla.org/en-US/docs/Web/API/Event) (`event`), and the returned value by this callback is ignored.
417417

418+
You can attach several callbacks to the same event of a DOM element by using the syntax `data-wp-on--[event]---[unique-id]` (note the three hyphens before the unique ID). Everything between `data-wp-on--` and the three hyphens is used as the event name, so `data-wp-on--click--counter` listens for an event named `click--counter`, not for `click`.
419+
420+
```html
421+
<button
422+
data-wp-on--click="actions.logTime"
423+
data-wp-on--click---counter="actions.countClick"
424+
>
425+
Click Me!
426+
</button>
427+
```
428+
418429
### `wp-on-window`
419430

420431
<div class="callout callout-info">
@@ -448,6 +459,8 @@ store( 'myPlugin', {
448459

449460
The callback passed as the reference receives [the event](https://developer.mozilla.org/en-US/docs/Web/API/Event) (`event`), and the returned value by this callback is ignored. When the element is removed from the DOM, the event listener is also removed.
450461

462+
You can attach several callbacks to the same window event by using the syntax `data-wp-on-window--[window-event]---[unique-id]` (note the three hyphens before the unique ID), like `data-wp-on-window--resize---log-width`.
463+
451464
### `wp-on-document`
452465

453466
<div class="callout callout-info">
@@ -481,14 +494,14 @@ store( 'myPlugin', {
481494

482495
The callback passed as the reference receives [the event](https://developer.mozilla.org/en-US/docs/Web/API/Event) (`event`), and the returned value by this callback is ignored. When the element is removed from the DOM, the event listener is also removed.
483496

497+
You can attach several callbacks to the same document event by using the syntax `data-wp-on-document--[document-event]---[unique-id]` (note the three hyphens before the unique ID), like `data-wp-on-document--keydown---log-key`.
498+
484499
### `wp-watch`
485500

486501
It runs a callback **when the node is created and runs it again when the state or context changes**.
487502

488503
You can attach several side effects to the same DOM element by using the syntax `data-wp-watch---[unique-id]` (note the three hyphens before the unique ID).
489504

490-
> **Deprecation notice:** The two-hyphen syntax `data-wp-watch--[unique-id]` is deprecated and will stop working in WordPress 7.1. Use three hyphens (`---`) for unique IDs.
491-
492505
The `unique-id` doesn't need to be unique globally. It just needs to be different from the other unique IDs of the `wp-watch` directives of that DOM element.
493506

494507
```html
@@ -547,8 +560,6 @@ This directive runs a callback **only when the node is created**.
547560

548561
You can attach several `wp-init` to the same DOM element by using the syntax `data-wp-init---[unique-id]` (note the three hyphens before the unique ID).
549562

550-
> **Deprecation notice:** The two-hyphen syntax `data-wp-init--[unique-id]` is deprecated and will stop working in WordPress 7.1. Use three hyphens (`---`) for unique IDs.
551-
552563
The `unique-id` doesn't need to be unique globally. It just needs to be different from the other unique IDs of the `wp-init` directives of that DOM element.
553564

554565
```html
@@ -597,8 +608,6 @@ You can use and compose hooks like `useState`, `useWatch`, or `useEffect` inside
597608

598609
You can attach several `wp-run` to the same DOM element by using the syntax `data-wp-run---[unique-id]` (note the three hyphens before the unique ID).
599610

600-
> **Deprecation notice:** The two-hyphen syntax `data-wp-run--[unique-id]` is deprecated and will stop working in WordPress 7.1. Use three hyphens (`---`) for unique IDs.
601-
602611
The `unique-id` doesn't need to be unique globally. It just needs to be different from the other unique IDs of the `wp-run` directives of that DOM element.
603612

604613
```html
@@ -776,6 +785,8 @@ And then, the string value `"state.isPlaying"` is used to assign the result of t
776785
</div>
777786
```
778787

788+
The `!` operator negates the referenced value. It only works with values, such as state, context, or derived state defined with a getter. If the reference points to a function, such as an action or a callback, the function is not called and the directive receives `undefined` instead (with a warning when `SCRIPT_DEBUG` is enabled). To negate the result of a computation, define it as derived state with a getter and negate that.
789+
779790
These values assigned to directives are **references** to a particular property in the store. They are wired to the directives automatically so that each directive “knows” what store element refers to, without any additional configuration.
780791

781792
Note that, by default, references point to properties in the current namespace, which is the one specified by the closest ancestor with a `data-wp-interactive` attribute. If you need to access a property from a different namespace, you can explicitly set the namespace where the property accessed is defined. The syntax is `namespace::reference`, replacing `namespace` with the appropriate value.
@@ -1025,7 +1036,7 @@ This approach enables some functionalities that make directives flexible and pow
10251036

10261037
#### On the client side
10271038

1028-
_In the `view.js` file of each block_ the developer can define both the state and the elements of the store referencing functions like actions, side effects or derived state.
1039+
*In the `view.js` file of each block* the developer can define both the state and the elements of the store referencing functions like actions, side effects or derived state.
10291040

10301041
The `store` method used to set the store in JavaScript can be imported from `@wordpress/interactivity`.
10311042

@@ -1058,7 +1069,7 @@ The state defined on the server with `wp_interactivity_state()` gets merged with
10581069

10591070
The `wp_interactivity_state` function receives two arguments, a `string` with the namespace that will be used as a reference and an [associative array](https://www.php.net/manual/en/language.types.array.php) containing the values.
10601071

1061-
_Example of store initialized from the server with a `state` = `{ someValue: 123 }`_
1072+
*Example of store initialized from the server with a `state` = `{ someValue: 123 }`*
10621073

10631074
```php
10641075
// render.php

‎packages/e2e-tests/plugins/interactive-blocks/directive-init/render.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<div
2020
data-testid="multiple inits"
2121
data-wp-context='{"isReady":[false,false],"calls":[0,0]}'
22-
data-wp-init--one="actions.initOne"
22+
data-wp-init---one="actions.initOne"
2323
data-wp-init---two="actions.initTwo"
2424
>
2525
<p data-wp-text="state.isReady" data-testid="isReady">false,false</p>

‎packages/e2e-tests/plugins/interactive-blocks/directive-on-document/render.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</div>
2727
<div
2828
data-wp-on-document--keydown="actions.keydownHandler"
29-
data-wp-on-document--keydown--second="actions.keydownSecondHandler"
29+
data-wp-on-document--keydown---second="actions.keydownSecondHandler"
3030
data-wp-on-document--keydown---third="actions.keydownThirdHandler"
3131
>
3232
<p data-wp-text="state.keydownHandler" data-testid="keydownHandler">no</p>

‎packages/e2e-tests/plugins/interactive-blocks/directive-on-window/render.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</div>
2424
<div
2525
data-wp-on-window--resize="actions.resizeHandler"
26-
data-wp-on-window--resize--second="actions.resizeSecondHandler"
26+
data-wp-on-window--resize---second="actions.resizeSecondHandler"
2727
data-wp-on-window--resize---third="actions.resizeThirdHandler"
2828
>
2929
<p data-wp-text="state.resizeHandler" data-testid="resizeHandler">no</p>

‎packages/e2e-tests/plugins/interactive-blocks/directive-on/render.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
<button
6767
data-testid="multiple handlers button"
6868
data-wp-on--click="actions.setClicked"
69-
data-wp-on--click--counter="actions.countClick"
69+
data-wp-on--click---counter="actions.countClick"
7070
data-wp-on--click---toggle="actions.toggle"
7171
>Click me!</button>
7272
</div>

‎packages/e2e-tests/plugins/interactive-blocks/directive-run/render.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
data-watch=""
4444
>
4545
<div
46-
data-wp-run--mounted="callbacks.updateIsMounted"
46+
data-wp-run---mounted="callbacks.updateIsMounted"
4747
data-wp-run---hooks="callbacks.useHooks"
4848
>
4949
Element with wp-run using hooks

‎packages/e2e-tests/plugins/interactive-blocks/directive-run/view.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ const html = `
3939
<div data-testid="navigated">yes</div>
4040
4141
<div
42-
data-wp-run--hydrated="callbacks.updateIsHydrated"
43-
data-wp-run--renderCount="callbacks.updateRenderCount"
42+
data-wp-run---hydrated="callbacks.updateIsHydrated"
43+
data-wp-run---renderCount="callbacks.updateRenderCount"
4444
data-wp-text="state.clickCount"
4545
></div>
4646
</div>

‎packages/e2e-tests/plugins/interactive-blocks/directive-watch/render.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
<div
3333
data-testid="multiple watches"
34-
data-wp-watch--one="callbacks.watch1"
34+
data-wp-watch---one="callbacks.watch1"
3535
data-wp-watch---two="callbacks.watch2"
3636
data-wp-bind--data-watch-one="state.watch1"
3737
data-wp-bind--data-watch-two="state.watch2"

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@
3232
<div data-wp-interactive="tovdom-islands">
3333
<div data-wp-ignore>
3434
<div data-wp-show-mock="state.falseValue">
35-
<span
36-
data-testid="inside an inner block of an isolated island"
37-
>
38-
This should be shown because it is inside an inner
39-
block of an isolated island.
35+
<span data-testid="inside an element with data-wp-ignore">
36+
This should not be shown because data-wp-ignore no
37+
longer prevents hydration.
4038
</span>
4139
</div>
4240
</div>
@@ -60,15 +58,14 @@
6058
<div>
6159
<div
6260
data-wp-interactive="tovdom-islands"
63-
data-wp-ignore
6461
>
6562
<div data-wp-show-mock="state.falseValue">
6663
<span
67-
data-testid="island inside inner block of isolated island"
64+
data-testid="island inside an inner element of another island"
6865
>
69-
This should not be shown because even though it
70-
is inside an inner block of an isolated island,
71-
it's inside an new island.
66+
This should not be shown because it is inside a
67+
new island nested in an inner element of another
68+
island.
7269
</span>
7370
</div>
7471
</div>

‎packages/e2e-tests/plugins/interactive-blocks/with-scope/render.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
?>
88

9-
<div data-wp-interactive="with-scope" data-wp-context='{"asyncCounter": 0, "syncCounter": 0}' data-wp-init--a='callbacks.asyncInit' data-wp-init--b='callbacks.syncInit'>
9+
<div data-wp-interactive="with-scope" data-wp-context='{"asyncCounter": 0, "syncCounter": 0}' data-wp-init---a='callbacks.asyncInit' data-wp-init---b='callbacks.syncInit'>
1010
<p data-wp-text="context.asyncCounter" data-testid="asyncCounter">0</p>
1111
<p data-wp-text="context.syncCounter" data-testid="syncCounter">0</p>
1212
</div>

0 commit comments

Comments
 (0)