@isograph/react-disposable-state 0.0.0-main-8a48dfd6 → 0.0.0-main-caa0e3a8
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
../.. | WARN Unsupported engine: wanted: {"node":"22.9.0"} (current: {"node":"v22.21.1","pnpm":"10.15.0"})
|
|
2
2
|
|
|
3
|
-
> @isograph/react-disposable-state@0.0.0-main-
|
|
3
|
+
> @isograph/react-disposable-state@0.0.0-main-caa0e3a8 compile-libs /home/runner/work/isograph/isograph/libs/isograph-react-disposable-state
|
|
4
4
|
> rimraf dist && tsc -p tsconfig.pkg.json
|
|
5
5
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@isograph/react-disposable-state",
|
|
3
|
-
"version": "0.0.0-main-
|
|
3
|
+
"version": "0.0.0-main-caa0e3a8",
|
|
4
4
|
"description": "Primitives for managing disposable state in React",
|
|
5
5
|
"homepage": "https://isograph.dev",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"author": "Isograph Labs",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@isograph/disposable-types": "0.0.0-main-
|
|
11
|
+
"@isograph/disposable-types": "0.0.0-main-caa0e3a8"
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|
|
14
14
|
"react": "^18.0.0 || ^19.0.0"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ItemCleanupPair } from '@isograph/disposable-types';
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { type MutableRefObject } from 'react';
|
|
3
3
|
import { create } from 'react-test-renderer';
|
|
4
4
|
import { assert, describe, expect, test, vi } from 'vitest';
|
|
5
5
|
import { CacheItem, CacheItemState } from './CacheItem';
|
|
@@ -14,7 +14,13 @@ function getState<T>(cacheItem: CacheItem<T>): CacheItemState<T> {
|
|
|
14
14
|
return (cacheItem as any).__state;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
function Suspender({
|
|
17
|
+
function Suspender({
|
|
18
|
+
promise,
|
|
19
|
+
isResolvedRef,
|
|
20
|
+
}: {
|
|
21
|
+
promise: Promise<unknown>;
|
|
22
|
+
isResolvedRef: MutableRefObject<boolean>;
|
|
23
|
+
}) {
|
|
18
24
|
if (!isResolvedRef.current) {
|
|
19
25
|
throw promise;
|
|
20
26
|
}
|
|
@@ -22,23 +28,18 @@ function Suspender({ promise, isResolvedRef }) {
|
|
|
22
28
|
}
|
|
23
29
|
|
|
24
30
|
function shortPromise() {
|
|
25
|
-
|
|
26
|
-
const promise = new Promise((_resolve) => {
|
|
27
|
-
resolve = _resolve;
|
|
28
|
-
});
|
|
31
|
+
const { promise, resolve } = Promise.withResolvers<void>();
|
|
29
32
|
|
|
30
33
|
setTimeout(resolve, 1);
|
|
31
34
|
return promise;
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
function promiseAndResolver() {
|
|
35
|
-
let resolve;
|
|
36
38
|
const isResolvedRef = {
|
|
37
39
|
current: false,
|
|
38
40
|
};
|
|
39
|
-
const promise =
|
|
40
|
-
|
|
41
|
-
});
|
|
41
|
+
const { promise, resolve } = Promise.withResolvers<void>();
|
|
42
|
+
|
|
42
43
|
return {
|
|
43
44
|
promise,
|
|
44
45
|
resolve: () => {
|
|
@@ -51,7 +52,7 @@ function promiseAndResolver() {
|
|
|
51
52
|
|
|
52
53
|
// The fact that sometimes we need to render in concurrent mode and sometimes
|
|
53
54
|
// not is a bit worrisome.
|
|
54
|
-
async function awaitableCreate(Component, isConcurrent) {
|
|
55
|
+
async function awaitableCreate(Component, isConcurrent: boolean) {
|
|
55
56
|
const element = create(
|
|
56
57
|
Component,
|
|
57
58
|
isConcurrent ? { unstable_isConcurrent: true } : undefined,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { type MutableRefObject } from 'react';
|
|
2
2
|
import { create } from 'react-test-renderer';
|
|
3
3
|
import { describe, expect, test, vi } from 'vitest';
|
|
4
4
|
import {
|
|
@@ -6,7 +6,13 @@ import {
|
|
|
6
6
|
useUpdatableDisposableState,
|
|
7
7
|
} from './useUpdatableDisposableState';
|
|
8
8
|
|
|
9
|
-
function Suspender({
|
|
9
|
+
function Suspender({
|
|
10
|
+
promise,
|
|
11
|
+
isResolvedRef,
|
|
12
|
+
}: {
|
|
13
|
+
isResolvedRef: MutableRefObject<boolean>;
|
|
14
|
+
promise: Promise<unknown>;
|
|
15
|
+
}) {
|
|
10
16
|
if (!isResolvedRef.current) {
|
|
11
17
|
throw promise;
|
|
12
18
|
}
|
|
@@ -43,7 +49,7 @@ function promiseAndResolver() {
|
|
|
43
49
|
|
|
44
50
|
// The fact that sometimes we need to render in concurrent mode and sometimes
|
|
45
51
|
// not is a bit worrisome.
|
|
46
|
-
async function awaitableCreate(Component, isConcurrent) {
|
|
52
|
+
async function awaitableCreate(Component, isConcurrent: boolean) {
|
|
47
53
|
const element = create(
|
|
48
54
|
Component,
|
|
49
55
|
isConcurrent ? { unstable_isConcurrent: true } : undefined,
|
|
@@ -377,7 +383,11 @@ if (false) {
|
|
|
377
383
|
}
|
|
378
384
|
|
|
379
385
|
let setState;
|
|
380
|
-
function ParentComponent({
|
|
386
|
+
function ParentComponent({
|
|
387
|
+
shouldMountRef,
|
|
388
|
+
}: {
|
|
389
|
+
shouldMountRef: MutableRefObject<boolean>;
|
|
390
|
+
}) {
|
|
381
391
|
const [, _setState] = React.useState();
|
|
382
392
|
setState = _setState;
|
|
383
393
|
return shouldMountRef.current ? (
|
|
@@ -450,7 +460,11 @@ if (false) {
|
|
|
450
460
|
}
|
|
451
461
|
|
|
452
462
|
let setState;
|
|
453
|
-
function ParentComponent({
|
|
463
|
+
function ParentComponent({
|
|
464
|
+
shouldMountRef,
|
|
465
|
+
}: {
|
|
466
|
+
shouldMountRef: MutableRefObject<boolean>;
|
|
467
|
+
}) {
|
|
454
468
|
const [, _setState] = React.useState();
|
|
455
469
|
setState = _setState;
|
|
456
470
|
return shouldMountRef.current ? <TestComponent /> : null;
|