@wordpress/data 10.46.0 → 10.47.0
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.
- package/CHANGELOG.md +2 -0
- package/package.json +10 -10
- package/src/components/use-select/test/suspense.js +25 -7
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/data",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.47.0",
|
|
4
4
|
"description": "Data module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -45,13 +45,13 @@
|
|
|
45
45
|
"types": "build-types",
|
|
46
46
|
"sideEffects": false,
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@wordpress/compose": "^
|
|
49
|
-
"@wordpress/deprecated": "^4.
|
|
50
|
-
"@wordpress/element": "^
|
|
51
|
-
"@wordpress/is-shallow-equal": "^5.
|
|
52
|
-
"@wordpress/priority-queue": "^3.
|
|
53
|
-
"@wordpress/private-apis": "^1.
|
|
54
|
-
"@wordpress/redux-routine": "^5.
|
|
48
|
+
"@wordpress/compose": "^8.0.0",
|
|
49
|
+
"@wordpress/deprecated": "^4.47.0",
|
|
50
|
+
"@wordpress/element": "^7.0.0",
|
|
51
|
+
"@wordpress/is-shallow-equal": "^5.47.0",
|
|
52
|
+
"@wordpress/priority-queue": "^3.47.0",
|
|
53
|
+
"@wordpress/private-apis": "^1.47.0",
|
|
54
|
+
"@wordpress/redux-routine": "^5.47.0",
|
|
55
55
|
"deepmerge": "^4.3.0",
|
|
56
56
|
"equivalent-key-map": "^0.2.2",
|
|
57
57
|
"is-plain-object": "^5.0.0",
|
|
@@ -64,10 +64,10 @@
|
|
|
64
64
|
"deep-freeze": "0.0.1"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"react": "^
|
|
67
|
+
"react": "^19.2.4"
|
|
68
68
|
},
|
|
69
69
|
"publishConfig": {
|
|
70
70
|
"access": "public"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "d653c5fd6161571a0c2ebde28553d6e25624eacc"
|
|
73
73
|
}
|
|
@@ -6,13 +6,13 @@ import { render, screen } from '@testing-library/react';
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
|
+
import { Component, Suspense } from '@wordpress/element';
|
|
9
10
|
import {
|
|
10
11
|
createRegistry,
|
|
11
12
|
createReduxStore,
|
|
12
13
|
useSuspenseSelect,
|
|
13
14
|
RegistryProvider,
|
|
14
15
|
} from '@wordpress/data';
|
|
15
|
-
import { Component, Suspense } from '@wordpress/element';
|
|
16
16
|
|
|
17
17
|
function createRegistryWithStore() {
|
|
18
18
|
const initialState = {
|
|
@@ -110,10 +110,12 @@ describe( 'useSuspenseSelect', () => {
|
|
|
110
110
|
render( <App /> );
|
|
111
111
|
await screen.findByLabelText( 'loaded' );
|
|
112
112
|
|
|
113
|
-
// Verify there were
|
|
114
|
-
//
|
|
115
|
-
//
|
|
116
|
-
|
|
113
|
+
// Verify there were 4 attempts to render:
|
|
114
|
+
// - initial render with `getToken` not being resolved and suspending, rendering fallback;
|
|
115
|
+
// - second render for sibling prerendering which collects all other suspending promises early;
|
|
116
|
+
// - third render after `getToken` is resolved and `getData` suspends;
|
|
117
|
+
// - final fourth render after all data got loaded.
|
|
118
|
+
expect( attempts ).toBe( 4 );
|
|
117
119
|
expect( renders ).toBe( 1 );
|
|
118
120
|
} );
|
|
119
121
|
|
|
@@ -229,7 +231,23 @@ describe( 'useSuspenseSelect', () => {
|
|
|
229
231
|
const slowLabel = await screen.findByLabelText( 'slow loaded' );
|
|
230
232
|
expect( slowLabel ).toHaveTextContent( 'slow' );
|
|
231
233
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
+
// Verify the number of renders. The reasoning behind is subtle but not that complicated:
|
|
235
|
+
// - initial render where both `FastUI` and `SlowUI` suspend and fallbacks are rendered;
|
|
236
|
+
// - second (async) render for sibling prerendering that tries to collect all suspending promises.
|
|
237
|
+
// Both `FastUI` and `SlowUI` suspend again but this time the result is not committed, its purpose
|
|
238
|
+
// was just to collect suspending promises.
|
|
239
|
+
// - `FastUI` renders for third time after its suspended promise is resolved. However, this render
|
|
240
|
+
// is _not_ committed because of "suspense fallback throttling". The render is delayed/throttled for 300ms
|
|
241
|
+
// so that the user doesn't see too many and too fast UI flashes. The fallback continues to be rendered.
|
|
242
|
+
// - `SlowUI` suspended promise is resolved and a third render is triggered. However, as the `FastUI` render
|
|
243
|
+
// is not yet committed, a _fourth_ render is triggered, to make sure that we'll be committing the most
|
|
244
|
+
// up-to-date state of the `FastUI` component.
|
|
245
|
+
//
|
|
246
|
+
// The above explains why there are 4 renders of `FastUI` and 3 renders of `SlowUI`. The non-obvious part
|
|
247
|
+
// is explained by a combination of two React features:
|
|
248
|
+
// - sibling prerendering that triggers an extra rerender after one component suspends;
|
|
249
|
+
// - fallback throttling that delays commit by 300ms and triggers an extra rerender.
|
|
250
|
+
expect( FastUI ).toHaveBeenCalledTimes( 4 );
|
|
251
|
+
expect( SlowUI ).toHaveBeenCalledTimes( 3 );
|
|
234
252
|
} );
|
|
235
253
|
} );
|