@wordpress/e2e-tests 7.20.0 → 7.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/package.json +9 -8
  3. package/plugins/interactive-blocks/directive-bind/render.php +1 -1
  4. package/plugins/interactive-blocks/directive-body/render.php +1 -1
  5. package/plugins/interactive-blocks/directive-class/render.php +1 -1
  6. package/plugins/interactive-blocks/directive-context/render.php +2 -2
  7. package/plugins/interactive-blocks/directive-context/view.js +10 -6
  8. package/plugins/interactive-blocks/{directive-slots → directive-each}/block.json +3 -3
  9. package/plugins/interactive-blocks/directive-each/render.php +226 -0
  10. package/plugins/interactive-blocks/directive-each/view.js +192 -0
  11. package/plugins/interactive-blocks/directive-init/render.php +1 -1
  12. package/plugins/interactive-blocks/directive-key/render.php +2 -2
  13. package/plugins/interactive-blocks/directive-key/view.js +7 -4
  14. package/plugins/interactive-blocks/directive-on/render.php +1 -1
  15. package/plugins/interactive-blocks/directive-on-document/block.json +15 -0
  16. package/plugins/interactive-blocks/directive-on-document/render.php +29 -0
  17. package/plugins/interactive-blocks/directive-on-document/view.js +39 -0
  18. package/plugins/interactive-blocks/directive-on-window/block.json +15 -0
  19. package/plugins/interactive-blocks/directive-on-window/render.php +26 -0
  20. package/plugins/interactive-blocks/directive-on-window/view.js +39 -0
  21. package/plugins/interactive-blocks/directive-priorities/render.php +1 -1
  22. package/plugins/interactive-blocks/directive-run/block.json +15 -0
  23. package/plugins/interactive-blocks/directive-run/render.php +54 -0
  24. package/plugins/interactive-blocks/directive-run/view.js +110 -0
  25. package/plugins/interactive-blocks/directive-style/render.php +1 -1
  26. package/plugins/interactive-blocks/directive-text/render.php +15 -1
  27. package/plugins/interactive-blocks/directive-text/view.js +4 -1
  28. package/plugins/interactive-blocks/directive-watch/render.php +1 -1
  29. package/plugins/interactive-blocks/negation-operator/render.php +1 -1
  30. package/plugins/interactive-blocks/router-navigate/render.php +2 -2
  31. package/plugins/interactive-blocks/router-navigate/view.js +5 -2
  32. package/plugins/interactive-blocks/router-regions/render.php +4 -4
  33. package/plugins/interactive-blocks/router-regions/view.js +5 -2
  34. package/plugins/interactive-blocks/store-tag/render.php +3 -3
  35. package/plugins/interactive-blocks/tovdom/render.php +1 -1
  36. package/plugins/interactive-blocks/tovdom-islands/render.php +1 -1
  37. package/plugins/interactive-blocks/with-scope/block.json +15 -0
  38. package/plugins/interactive-blocks/with-scope/render.php +14 -0
  39. package/plugins/interactive-blocks/with-scope/view.js +20 -0
  40. package/plugins/interactive-blocks.php +19 -10
  41. package/specs/editor/various/__snapshots__/pattern-blocks.test.js.snap +0 -6
  42. package/specs/editor/various/pattern-blocks.test.js +8 -117
  43. package/plugins/dataviews.php +0 -25
  44. package/plugins/interactive-blocks/directive-slots/render.php +0 -69
  45. package/plugins/interactive-blocks/directive-slots/view.js +0 -20
  46. package/specs/editor/fixtures/menu-items-request-fixture.json +0 -84
  47. package/specs/editor/fixtures/menu-items-response-fixture.json +0 -1261
  48. package/specs/editor/various/__snapshots__/block-grouping.test.js.snap +0 -115
  49. package/specs/editor/various/__snapshots__/embedding.test.js.snap +0 -67
  50. package/specs/editor/various/block-grouping.test.js +0 -283
  51. package/specs/editor/various/embedding.test.js +0 -303
  52. package/specs/editor/various/typewriter.test.js +0 -260
@@ -0,0 +1,39 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { store, directive } from '@wordpress/interactivity';
5
+
6
+ // Mock `data-wp-show` directive to test when things are removed from the
7
+ // DOM. Replace with `data-wp-show` when it's ready.
8
+ directive(
9
+ 'show-mock',
10
+ ( { directives: { 'show-mock': showMock }, element, evaluate } ) => {
11
+ const entry = showMock.find( ( { suffix } ) => suffix === 'default' );
12
+ if ( ! evaluate( entry ) ) {
13
+ return null;
14
+ }
15
+ return element;
16
+ }
17
+ );
18
+
19
+ const { state } = store( 'directive-on-document', {
20
+ state: {
21
+ counter: 0,
22
+ isVisible: true,
23
+ isEventAttached: 'no',
24
+ },
25
+ callbacks: {
26
+ keydownHandler() {
27
+ state.counter += 1;
28
+ },
29
+ init() {
30
+ state.isEventAttached = 'yes';
31
+ },
32
+ },
33
+ actions: {
34
+ visibilityHandler: () => {
35
+ state.isEventAttached = 'no';
36
+ state.isVisible = ! state.isVisible;
37
+ },
38
+ }
39
+ } );
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "https://schemas.wp.org/trunk/block.json",
3
+ "apiVersion": 2,
4
+ "name": "test/directive-on-window",
5
+ "title": "E2E Interactivity tests - directive on window",
6
+ "category": "text",
7
+ "icon": "heart",
8
+ "description": "",
9
+ "supports": {
10
+ "interactivity": true
11
+ },
12
+ "textdomain": "e2e-interactivity",
13
+ "viewScript": "directive-on-window-view",
14
+ "render": "file:./render.php"
15
+ }
@@ -0,0 +1,26 @@
1
+ <?php
2
+ /**
3
+ * HTML for testing the directive `data-wp-on`.
4
+ *
5
+ * @package gutenberg-test-interactive-blocks
6
+ */
7
+
8
+ wp_enqueue_script_module( 'directive-on-window-view' );
9
+ ?>
10
+
11
+ <div data-wp-interactive='{ "namespace": "directive-on-window" }'>
12
+ <button
13
+ data-wp-on--click="actions.visibilityHandler"
14
+ data-testid="visibility">
15
+ Switch visibility
16
+ </button>
17
+ <div data-wp-text="state.isEventAttached" data-testid="isEventAttached">no</div>
18
+ <div data-wp-show-mock="state.isVisible">
19
+ <div
20
+ data-wp-on-window--resize="callbacks.resizeHandler"
21
+ data-wp-init="callbacks.init"
22
+ >
23
+ <p data-wp-text="state.counter" data-testid="counter">0</p>
24
+ </div>
25
+ </div>
26
+ </div>
@@ -0,0 +1,39 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { store, directive } from '@wordpress/interactivity';
5
+
6
+ // Mock `data-wp-show` directive to test when things are removed from the
7
+ // DOM. Replace with `data-wp-show` when it's ready.
8
+ directive(
9
+ 'show-mock',
10
+ ( { directives: { 'show-mock': showMock }, element, evaluate } ) => {
11
+ const entry = showMock.find( ( { suffix } ) => suffix === 'default' );
12
+ if ( ! evaluate( entry ) ) {
13
+ return null;
14
+ }
15
+ return element;
16
+ }
17
+ );
18
+
19
+ const { state } = store( 'directive-on-window', {
20
+ state: {
21
+ counter: 0,
22
+ isVisible: true,
23
+ isEventAttached: 'no',
24
+ },
25
+ callbacks: {
26
+ resizeHandler() {
27
+ state.counter += 1;
28
+ },
29
+ init() {
30
+ state.isEventAttached = 'yes';
31
+ }
32
+ },
33
+ actions: {
34
+ visibilityHandler: () => {
35
+ state.isEventAttached = 'no';
36
+ state.isVisible = ! state.isVisible;
37
+ },
38
+ }
39
+ } );
@@ -5,7 +5,7 @@
5
5
  * @package gutenberg-test-interactive-blocks
6
6
  */
7
7
 
8
- gutenberg_enqueue_module( 'directive-priorities-view' );
8
+ wp_enqueue_script_module( 'directive-priorities-view' );
9
9
  ?>
10
10
 
11
11
  <div data-wp-interactive='{ "namespace": "directive-priorities" }'>
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "https://schemas.wp.org/trunk/block.json",
3
+ "apiVersion": 2,
4
+ "name": "test/directive-run",
5
+ "title": "E2E Interactivity tests - directive run",
6
+ "category": "text",
7
+ "icon": "heart",
8
+ "description": "",
9
+ "supports": {
10
+ "interactivity": true
11
+ },
12
+ "textdomain": "e2e-interactivity",
13
+ "viewScript": "directive-run-view",
14
+ "render": "file:./render.php"
15
+ }
@@ -0,0 +1,54 @@
1
+ <?php
2
+ /**
3
+ * HTML for testing the directive `data-wp-run`.
4
+ *
5
+ * @package gutenberg-test-interactive-blocks
6
+ */
7
+
8
+ wp_enqueue_script_module( 'directive-run-view' );
9
+ ?>
10
+
11
+ <div
12
+ data-wp-interactive='{ "namespace": "directive-run" }'
13
+ data-wp-router-region='test-directive-run'
14
+ >
15
+ <div data-testid="hydrated" data-wp-text="state.isHydrated"></div>
16
+ <div data-testid="mounted" data-wp-text="state.isMounted"></div>
17
+ <div data-testid="renderCount" data-wp-text="state.renderCount"></div>
18
+ <div data-testid="navigated">no</div>
19
+
20
+ <div
21
+ data-wp-run--hydrated="callbacks.updateIsHydrated"
22
+ data-wp-run--renderCount="callbacks.updateRenderCount"
23
+ data-wp-text="state.clickCount"
24
+ ></div>
25
+ </div>
26
+
27
+ <div data-wp-interactive='{ "namespace": "directive-run" }' >
28
+ <button data-testid="toggle" data-wp-on--click="actions.toggle">
29
+ Toggle
30
+ </button>
31
+
32
+ <button data-testid="increment" data-wp-on--click="actions.increment">
33
+ Increment
34
+ </button>
35
+
36
+ <button data-testid="navigate" data-wp-on--click="actions.navigate">
37
+ Navigate
38
+ </button>
39
+
40
+ <!-- Hook execution results are stored in this element as attributes. -->
41
+ <div
42
+ data-testid="wp-run hooks results"
43
+ data-wp-show-children="state.isOpen"
44
+ data-init=""
45
+ data-watch=""
46
+ >
47
+ <div
48
+ data-wp-run--mounted="callbacks.updateIsMounted"
49
+ data-wp-run--hooks="callbacks.useHooks"
50
+ >
51
+ Element with wp-run using hooks
52
+ </div>
53
+ </div>
54
+ </div>
@@ -0,0 +1,110 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import {
5
+ store,
6
+ directive,
7
+ useInit,
8
+ useWatch,
9
+ cloneElement,
10
+ getElement,
11
+ } from '@wordpress/interactivity';
12
+
13
+ // Custom directive to show hide the content elements in which it is placed.
14
+ directive(
15
+ 'show-children',
16
+ ( { directives: { 'show-children': showChildren }, element, evaluate } ) => {
17
+ const entry = showChildren.find(
18
+ ( { suffix } ) => suffix === 'default'
19
+ );
20
+ return evaluate( entry )
21
+ ? element
22
+ : cloneElement( element, { children: null } );
23
+ },
24
+ { priority: 9 }
25
+ );
26
+
27
+ const html = `
28
+ <div
29
+ data-wp-interactive='{ "namespace": "directive-run" }'
30
+ data-wp-router-region='test-directive-run'
31
+ >
32
+ <div data-testid="hydrated" data-wp-text="state.isHydrated"></div>
33
+ <div data-testid="mounted" data-wp-text="state.isMounted"></div>
34
+ <div data-testid="renderCount" data-wp-text="state.renderCount"></div>
35
+ <div data-testid="navigated">yes</div>
36
+
37
+ <div
38
+ data-wp-run--hydrated="callbacks.updateIsHydrated"
39
+ data-wp-run--renderCount="callbacks.updateRenderCount"
40
+ data-wp-text="state.clickCount"
41
+ ></div>
42
+ </div>
43
+ `;
44
+
45
+ const { state } = store( 'directive-run', {
46
+ state: {
47
+ isOpen: false,
48
+ isHydrated: 'no',
49
+ isMounted: 'no',
50
+ renderCount: 0,
51
+ clickCount: 0
52
+ },
53
+ actions: {
54
+ toggle() {
55
+ state.isOpen = ! state.isOpen;
56
+ },
57
+ increment() {
58
+ state.clickCount = state.clickCount + 1;
59
+ },
60
+ *navigate() {
61
+ const { actions } = yield import(
62
+ "@wordpress/interactivity-router"
63
+ );
64
+ return actions.navigate( window.location, {
65
+ force: true,
66
+ html,
67
+ } );
68
+ },
69
+ },
70
+ callbacks: {
71
+ updateIsHydrated() {
72
+ setTimeout( () => ( state.isHydrated = 'yes' ) );
73
+ },
74
+ updateIsMounted() {
75
+ setTimeout( () => ( state.isMounted = 'yes' ) );
76
+ },
77
+ updateRenderCount() {
78
+ setTimeout( () => ( state.renderCount = state.renderCount + 1 ) );
79
+ },
80
+ useHooks() {
81
+ // Runs only on first render.
82
+ useInit( () => {
83
+ const { ref } = getElement();
84
+ ref
85
+ .closest( '[data-testid="wp-run hooks results"]')
86
+ .setAttribute( 'data-init', 'initialized' );
87
+ return () => {
88
+ ref
89
+ .closest( '[data-testid="wp-run hooks results"]')
90
+ .setAttribute( 'data-init', 'cleaned up' );
91
+ };
92
+ } );
93
+
94
+ // Runs whenever a signal consumed inside updates its value. Also
95
+ // executes for the first render.
96
+ useWatch( () => {
97
+ const { ref } = getElement();
98
+ const { clickCount } = state;
99
+ ref
100
+ .closest( '[data-testid="wp-run hooks results"]')
101
+ .setAttribute( 'data-watch', clickCount );
102
+ return () => {
103
+ ref
104
+ .closest( '[data-testid="wp-run hooks results"]')
105
+ .setAttribute( 'data-watch', 'cleaned up' );
106
+ };
107
+ } );
108
+ }
109
+ }
110
+ } );
@@ -5,7 +5,7 @@
5
5
  * @package gutenberg-test-interactive-blocks
6
6
  */
7
7
 
8
- gutenberg_enqueue_module( 'directive-style-view' );
8
+ wp_enqueue_script_module( 'directive-style-view' );
9
9
  ?>
10
10
 
11
11
  <div data-wp-interactive='{ "namespace": "directive-style" }'>
@@ -5,7 +5,7 @@
5
5
  * @package gutenberg-test-interactive-blocks
6
6
  */
7
7
 
8
- gutenberg_enqueue_module( 'directive-text-view' );
8
+ wp_enqueue_script_module( 'directive-text-view' );
9
9
  ?>
10
10
 
11
11
  <div data-wp-interactive='{ "namespace": "directive-context" }'>
@@ -34,4 +34,18 @@ gutenberg_enqueue_module( 'directive-text-view' );
34
34
  Toggle Context Text
35
35
  </button>
36
36
  </div>
37
+ <div>
38
+ <span
39
+ data-wp-text="state.component"
40
+ data-testid="show state component"
41
+ ></span>
42
+ <span
43
+ data-wp-text="state.number"
44
+ data-testid="show state number"
45
+ ></span>
46
+ <span
47
+ data-wp-text="state.boolean"
48
+ data-testid="show state boolean"
49
+ ></span>
50
+ </div>
37
51
  </div>
@@ -1,11 +1,14 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { store, getContext } from '@wordpress/interactivity';
4
+ import { store, getContext, createElement } from '@wordpress/interactivity';
5
5
 
6
6
  const { state } = store( 'directive-context', {
7
7
  state: {
8
8
  text: 'Text 1',
9
+ component: () => (createElement( 'div', {}, state.text )),
10
+ number: 1,
11
+ boolean: true
9
12
  },
10
13
  actions: {
11
14
  toggleStateText() {
@@ -5,7 +5,7 @@
5
5
  * @package gutenberg-test-interactive-blocks
6
6
  */
7
7
 
8
- gutenberg_enqueue_module( 'directive-watch-view' );
8
+ wp_enqueue_script_module( 'directive-watch-view' );
9
9
  ?>
10
10
 
11
11
  <div data-wp-interactive='{ "namespace": "directive-watch" }'>
@@ -5,7 +5,7 @@
5
5
  * @package gutenberg-test-interactive-blocks
6
6
  */
7
7
 
8
- gutenberg_enqueue_module( 'negation-operator-view' );
8
+ wp_enqueue_script_module( 'negation-operator-view' );
9
9
  ?>
10
10
 
11
11
  <div data-wp-interactive='{ "namespace": "negation-operator" }'>
@@ -7,12 +7,12 @@
7
7
  * @phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
8
8
  */
9
9
 
10
- gutenberg_enqueue_module( 'router-navigate-view' );
10
+ wp_enqueue_script_module( 'router-navigate-view' );
11
11
  ?>
12
12
 
13
13
  <div
14
14
  data-wp-interactive='{ "namespace": "router" }'
15
- data-wp-navigation-id="region-1"
15
+ data-wp-router-region="region-1"
16
16
  >
17
17
  <h2 data-testid="title"><?php echo $attributes['title']; ?></h2>
18
18
 
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { store, navigate } from '@wordpress/interactivity';
4
+ import { store } from '@wordpress/interactivity';
5
5
 
6
6
  const { state } = store( 'router', {
7
7
  state: {
@@ -19,7 +19,10 @@ const { state } = store( 'router', {
19
19
  const force = e.target.dataset.forceNavigation === 'true';
20
20
  const { timeout } = state;
21
21
 
22
- yield navigate( e.target.href, { force, timeout } );
22
+ const { actions } = yield import(
23
+ "@wordpress/interactivity-router"
24
+ );
25
+ yield actions.navigate( e.target.href, { force, timeout } );
23
26
 
24
27
  state.navigations -= 1;
25
28
 
@@ -7,14 +7,14 @@
7
7
  * @phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
8
8
  */
9
9
 
10
- gutenberg_enqueue_module( 'router-regions-view' );
10
+ wp_enqueue_script_module( 'router-regions-view' );
11
11
  ?>
12
12
 
13
13
  <section>
14
14
  <h2>Region 1</h2>
15
15
  <div
16
16
  data-wp-interactive='{"namespace": "router-regions"}'
17
- data-wp-navigation-id="region-1"
17
+ data-wp-router-region="region-1"
18
18
  >
19
19
  <p
20
20
  data-testid="region-1-text"
@@ -58,7 +58,7 @@ gutenberg_enqueue_module( 'router-regions-view' );
58
58
  <h2>Region 2</h2>
59
59
  <div
60
60
  data-wp-interactive='{"namespace": "router-regions"}'
61
- data-wp-navigation-id="region-2"
61
+ data-wp-router-region="region-2"
62
62
  >
63
63
  <p
64
64
  data-testid="region-2-text"
@@ -88,7 +88,7 @@ gutenberg_enqueue_module( 'router-regions-view' );
88
88
  <h2>Nested region</h2>
89
89
  <div
90
90
  data-wp-interactive='{"namespace": "router-regions"}'
91
- data-wp-navigation-id="nested-region"
91
+ data-wp-router-region="nested-region"
92
92
  >
93
93
  <p
94
94
  data-testid="nested-region-ssr"
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { store, navigate, getContext } from '@wordpress/interactivity';
4
+ import { store, getContext } from '@wordpress/interactivity';
5
5
 
6
6
  const { state } = store( 'router-regions', {
7
7
  state: {
@@ -19,7 +19,10 @@ const { state } = store( 'router-regions', {
19
19
  router: {
20
20
  *navigate( e ) {
21
21
  e.preventDefault();
22
- yield navigate( e.target.href );
22
+ const { actions } = yield import(
23
+ "@wordpress/interactivity-router"
24
+ );
25
+ yield actions.navigate( e.target.href );
23
26
  },
24
27
  back() {
25
28
  history.back();
@@ -7,7 +7,7 @@
7
7
  * @phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
8
8
  */
9
9
 
10
- gutenberg_enqueue_module( 'store-tag-view' );
10
+ wp_enqueue_script_module( 'store-tag-view' );
11
11
 
12
12
  // These variables simulates SSR.
13
13
  $test_store_tag_counter = 'ok' === $attributes['condition'] ? 3 : 0;
@@ -49,7 +49,7 @@ $test_store_tag_double = $test_store_tag_counter * 2;
49
49
  if ( 'missing' !== $attributes['condition'] ) {
50
50
 
51
51
  if ( 'ok' === $attributes['condition'] ) {
52
- $test_store_tag_json = '{ "store-tag": { "counter": { "value": 3 } } }';
52
+ $test_store_tag_json = '{ "state": { "store-tag": { "counter": { "value": 3 } } } }';
53
53
  }
54
54
 
55
55
  if ( 'corrupted-json' === $attributes['condition'] ) {
@@ -61,7 +61,7 @@ if ( 'missing' !== $attributes['condition'] ) {
61
61
  }
62
62
 
63
63
  echo <<<HTML
64
- <script type="application/json" id="wp-interactivity-initial-state">
64
+ <script type="application/json" id="wp-interactivity-data">
65
65
  $test_store_tag_json
66
66
  </script>
67
67
  HTML;
@@ -9,7 +9,7 @@ $plugin_url = plugin_dir_url( __DIR__ );
9
9
  $src_proc_ins = $plugin_url . 'tovdom/processing-instructions.js';
10
10
  $src_cdata = $plugin_url . 'tovdom/cdata.js';
11
11
 
12
- gutenberg_enqueue_module( 'tovdom-view' );
12
+ wp_enqueue_script_module( 'tovdom-view' );
13
13
  ?>
14
14
 
15
15
  <div data-wp-interactive='{ "namespace": "tovdom" }'>
@@ -5,7 +5,7 @@
5
5
  * @package gutenberg-test-interactive-blocks
6
6
  */
7
7
 
8
- gutenberg_enqueue_module( 'tovdom-islands-view' );
8
+ wp_enqueue_script_module( 'tovdom-islands-view' );
9
9
  ?>
10
10
 
11
11
  <div>
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "https://schemas.wp.org/trunk/block.json",
3
+ "apiVersion": 2,
4
+ "name": "test/with-scope",
5
+ "title": "E2E Interactivity tests - with scope",
6
+ "category": "text",
7
+ "icon": "heart",
8
+ "description": "",
9
+ "supports": {
10
+ "interactivity": true
11
+ },
12
+ "textdomain": "e2e-interactivity",
13
+ "viewScript": "with-scope-view",
14
+ "render": "file:./render.php"
15
+ }
@@ -0,0 +1,14 @@
1
+ <?php
2
+ /**
3
+ * HTML for testing the directive `data-wp-on`.
4
+ *
5
+ * @package gutenberg-test-interactive-blocks
6
+ */
7
+
8
+ wp_enqueue_script_module( 'with-scope-view' );
9
+ ?>
10
+
11
+ <div data-wp-interactive='{ "namespace": "with-scope" }' data-wp-context='{"asyncCounter": 0, "syncCounter": 0}' data-wp-init--a='callbacks.asyncInit' data-wp-init--b='callbacks.syncInit'>
12
+ <p data-wp-text="context.asyncCounter" data-testid="asyncCounter">0</p>
13
+ <p data-wp-text="context.syncCounter" data-testid="syncCounter">0</p>
14
+ </div>
@@ -0,0 +1,20 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { store, getContext, withScope } from '@wordpress/interactivity';
5
+
6
+ store( 'with-scope', {
7
+ callbacks: {
8
+ asyncInit: () => {
9
+ setTimeout( withScope(function*() {
10
+ yield new Promise(resolve => setTimeout(resolve, 1));
11
+ const context = getContext()
12
+ context.asyncCounter += 1;
13
+ }, 1 ));
14
+ },
15
+ syncInit: () => {
16
+ const context = getContext()
17
+ context.syncCounter += 1;
18
+ }
19
+ },
20
+ } );
@@ -21,26 +21,35 @@ add_action(
21
21
 
22
22
  $view_file = plugin_dir_url( $block_folder ) . $name . '/' . 'view.js';
23
23
 
24
- gutenberg_register_module(
24
+ wp_register_script_module(
25
25
  $name . '-view',
26
26
  $view_file,
27
- array( '@wordpress/interactivity' ),
28
- filemtime( $view_file ),
29
- true
27
+ array(
28
+ '@wordpress/interactivity',
29
+ array(
30
+ 'id' => '@wordpress/interactivity-router',
31
+ 'import' => 'dynamic',
32
+ ),
33
+ ),
34
+ filemtime( $view_file )
30
35
  );
31
36
 
32
37
  register_block_type_from_metadata( $block_folder );
33
38
  }
34
39
  }
35
40
 
36
- // Temporary fix to disable SSR of directives during E2E testing. This
37
- // is required at this moment, as SSR for directives is not stabilized
38
- // yet and we need to ensure hydration works, even when the rendered
39
- // HTML is not correct or malformed.
40
- if ( 'true' === $_GET['disable_directives_ssr'] ) {
41
+ /*
42
+ * Disable the server directive processing during E2E testing. This is
43
+ * required to ensure that client hydration works even when the rendered
44
+ * HTML contains unbalanced tags and it couldn't be processed in the server.
45
+ */
46
+ if ( 'true' === $_GET['disable_server_directive_processing'] ) {
47
+ // Ensure the interactivity API is loaded.
48
+ wp_interactivity();
49
+ // But remove the server directive processing.
41
50
  remove_filter(
42
51
  'render_block_data',
43
- 'gutenberg_interactivity_mark_root_blocks'
52
+ 'wp_interactivity_process_directives_of_interactive_blocks'
44
53
  );
45
54
  }
46
55
  }
@@ -1,11 +1,5 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`Pattern blocks allows conversion back to blocks when the reusable block has unsaved edits 1`] = `
4
- "<!-- wp:paragraph -->
5
- <p>12</p>
6
- <!-- /wp:paragraph -->"
7
- `;
8
-
9
3
  exports[`Pattern blocks can be created from multiselection and converted back to regular blocks 1`] = `
10
4
  "<!-- wp:paragraph -->
11
5
  <p>Hello there!</p>