Skip to content

Commit 615df9c

Browse files
authored
[v2] breaking: require react 18 and drop use-sync-external-store (#819)
* [v2] breaking: require react 18 and drop use-sync-external-store * drop tests pre react 18 * wip: cannot use react 17 for prd test * drop production test which is impossible * esm? * fix regex * fix sed
1 parent 204e073 commit 615df9c

6 files changed

+15
-37
lines changed

.github/workflows/test-multiple-builds.yml

+4-8
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
build: [cjs, umd] # [cjs, esm, umd, system]
16-
env: [development, production]
15+
build: [cjs, esm, umd] # [cjs, esm, umd, system]
16+
env: [development] # [development, production]
1717
steps:
1818
- uses: actions/checkout@v2
1919
- uses: actions/setup-node@v2
@@ -23,10 +23,6 @@ jobs:
2323
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
2424
- run: yarn install --frozen-lockfile --check-files
2525
- run: yarn build
26-
- name: Use React 17 for production test
27-
if: ${{ matrix.env == 'production' }}
28-
run: |
29-
3026
- name: Patch for DEV-ONLY
3127
if: ${{ matrix.env == 'development' }}
3228
run: |
@@ -44,8 +40,8 @@ jobs:
4440
- name: Patch for ESM
4541
if: ${{ matrix.build == 'esm' }}
4642
run: |
47-
sed -i~ "s/<rootDir>\/src\(.*\)\.ts/<rootDir>\/dist\/esm\1.js" package.json
48-
sed -i~ "1s/^/import.meta.env=import.meta.env||{};import.meta.env.MODE='${NODE_ENV}';/" tests.ts tests/*.tsx
43+
sed -i~ "s/<rootDir>\/src\(.*\)\.ts/<rootDir>\/dist\/esm\1.js/" package.json
44+
sed -i~ "1s/^/import.meta.env=import.meta.env||{};import.meta.env.MODE='${NODE_ENV}';/" tests/*.ts tests/*.tsx
4945
env:
5046
NODE_ENV: ${{ matrix.env }}
5147
- name: Patch for UMD

.github/workflows/test-multiple-versions.yml

-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ jobs:
2727
fail-fast: false
2828
matrix:
2929
react:
30-
- 16.8.0
31-
- 16.9.0
32-
- 17.0.0
3330
- 18.0.0
3431
- 18.1.0
3532
- 18.2.0

package.json

+3-5
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@
108108
"homepage": "https://github.com/pmndrs/valtio",
109109
"dependencies": {
110110
"proxy-compare": "2.5.1",
111-
"derive-valtio": "0.1.0",
112-
"use-sync-external-store": "1.2.0"
111+
"derive-valtio": "0.1.0"
113112
},
114113
"devDependencies": {
115114
"@babel/core": "^7.23.2",
@@ -130,7 +129,6 @@
130129
"@types/jsdom": "^21.1.4",
131130
"@types/react": "^18.2.34",
132131
"@types/react-dom": "^18.2.14",
133-
"@types/use-sync-external-store": "^0.0.5",
134132
"@typescript-eslint/eslint-plugin": "^6.9.1",
135133
"@typescript-eslint/parser": "^6.9.1",
136134
"@vitest/coverage-v8": "0.33.0",
@@ -166,8 +164,8 @@
166164
"vitest": "0.33.0"
167165
},
168166
"peerDependencies": {
169-
"@types/react": ">=16.8",
170-
"react": ">=16.8"
167+
"@types/react": ">=18.0",
168+
"react": ">=18.0"
171169
},
172170
"peerDependenciesMeta": {
173171
"@types/react": {

rollup.config.js

-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ function createESMConfig(input, output) {
7272
'import.meta.env?.MODE':
7373
'(import.meta.env ? import.meta.env.MODE : undefined)',
7474
}),
75-
// a workround for #410
76-
'use-sync-external-store/shim': 'use-sync-external-store/shim/index.js',
7775
delimiters: ['\\b', '\\b(?!(\\.|/))'],
7876
preventAssignment: true,
7977
}),

src/react.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import { useCallback, useDebugValue, useEffect, useMemo, useRef } from 'react'
1+
import {
2+
useCallback,
3+
useDebugValue,
4+
useEffect,
5+
useMemo,
6+
useRef,
7+
useSyncExternalStore,
8+
} from 'react'
29
import {
310
affectedToPathList,
411
createProxy as createProxyToCompare,
512
isChanged,
613
} from 'proxy-compare'
7-
// import { useSyncExternalStore } from 'use-sync-external-store/shim'
8-
// This doesn't work in ESM, because use-sync-external-store only exposes CJS.
9-
// See: https://github.com/pmndrs/valtio/issues/452
10-
// The following is a workaround until ESM is supported.
11-
// eslint-disable-next-line import/extensions
12-
import useSyncExternalStoreExports from 'use-sync-external-store/shim'
1314
import { snapshot, subscribe } from './vanilla.ts'
1415
import type { INTERNAL_Snapshot as Snapshot } from './vanilla.ts'
1516

16-
const { useSyncExternalStore } = useSyncExternalStoreExports
17-
1817
const useAffectedDebugValue = (
1918
state: object,
2019
affected: WeakMap<object, unknown>,

yarn.lock

-10
Original file line numberDiff line numberDiff line change
@@ -1691,11 +1691,6 @@
16911691
resolved "https://registry.yarnpkg.com/@types/tough-cookie/-/tough-cookie-4.0.4.tgz#cf2f0c7c51b985b6afecea73eb2cd65421ecb717"
16921692
integrity sha512-95Sfz4nvMAb0Nl9DTxN3j64adfwfbBPEYq14VN7zT5J5O2M9V6iZMIIQU1U+pJyl9agHYHNCqhCXgyEtIRRa5A==
16931693

1694-
"@types/use-sync-external-store@^0.0.5":
1695-
version "0.0.5"
1696-
resolved "https://registry.yarnpkg.com/@types/use-sync-external-store/-/use-sync-external-store-0.0.5.tgz#a4416edea87d78115c8339f668775c5ba102653d"
1697-
integrity sha512-+fHc7rdrgMIng29ISUqNjsbPl1EMo1PCDh/+16HNlTOJeQzs6c9Om23rVizETd3dDx4YM+aWGbyF/KP4FUwZyg==
1698-
16991694
"@typescript-eslint/eslint-plugin@^6.9.1":
17001695
version "6.9.1"
17011696
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.9.1.tgz#d8ce497dc0ed42066e195c8ecc40d45c7b1254f4"
@@ -5051,11 +5046,6 @@ url-parse@^1.5.3:
50515046
querystringify "^2.1.1"
50525047
requires-port "^1.0.0"
50535048

5054-
5055-
version "1.2.0"
5056-
resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz#7dbefd6ef3fe4e767a0cf5d7287aacfb5846928a"
5057-
integrity sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==
5058-
50595049
v8-to-istanbul@^9.1.0:
50605050
version "9.1.3"
50615051
resolved "https://registry.yarnpkg.com/v8-to-istanbul/-/v8-to-istanbul-9.1.3.tgz#ea456604101cd18005ac2cae3cdd1aa058a6306b"

0 commit comments

Comments
 (0)