Skip to content

Commit e7184db

Browse files
committed
feat: upgrade to react compiler v1
1 parent 3ed77a3 commit e7184db

File tree

8 files changed

+45
-70
lines changed

8 files changed

+45
-70
lines changed

.eslintrc.cjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = {
88
},
99
extends: [
1010
'plugin:react/recommended',
11+
'plugin:react-hooks/recommended',
1112
'plugin:react/jsx-runtime',
1213
'eslint:recommended',
1314
'plugin:prettier/recommended',
@@ -33,7 +34,6 @@ module.exports = {
3334
'react/prop-types': 'off',
3435
'react-hooks/exhaustive-deps': 'error', // Checks effect dependencies
3536
'react-hooks/rules-of-hooks': 'error', // Checks rules of Hooks
36-
'react-hooks/react-compiler': 'error',
3737
'react/no-unescaped-entities': 'off',
3838
'simple-import-sort/exports': 'warn',
3939
'simple-import-sort/imports': 'warn',
@@ -53,6 +53,7 @@ module.exports = {
5353
},
5454
extends: [
5555
'plugin:react/recommended',
56+
'plugin:react-hooks/recommended',
5657
'plugin:react/jsx-runtime',
5758
'eslint:recommended',
5859
'plugin:prettier/recommended',

.github/workflows/react-compiler.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
with:
2424
cache: pnpm
2525
node-version: lts/*
26-
- run: pnpm -r up --ignore-scripts react-compiler-runtime@rc babel-plugin-react-compiler@rc eslint-plugin-react-hooks@rc
26+
- run: pnpm -r up --ignore-scripts react-compiler-runtime@latest babel-plugin-react-compiler@latest eslint-plugin-react-hooks@latest
2727
- uses: actions/create-github-app-token@v2
2828
id: generate-token
2929
with:
@@ -39,7 +39,7 @@ jobs:
3939
- if: steps.check-changes.outputs.changed == 'true'
4040
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7
4141
with:
42-
body: I ran `pnpm -r up react-compiler-runtime@rc babel-plugin-react-compiler@rc eslint-plugin-react-hooks@rc` 🧑‍💻
42+
body: I ran `pnpm -r up react-compiler-runtime@latest babel-plugin-react-compiler@latest eslint-plugin-react-hooks@latest` 🧑‍💻
4343
branch: actions/react-compiler
4444
commit-message: "fix(deps): update react compiler dependencies 🤖 ✨"
4545
labels: 🤖 bot

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
"@types/react-dom": "^19.2.2",
149149
"@typescript-eslint/eslint-plugin": "^7.18.0",
150150
"@typescript-eslint/parser": "^7.18.0",
151-
"babel-plugin-react-compiler": "19.1.0-rc.2",
151+
"babel-plugin-react-compiler": "1.0.0",
152152
"commitizen": "^4.3.1",
153153
"commitlint": "^19.8.1",
154154
"eslint": "^8.57.1",
@@ -157,7 +157,7 @@
157157
"eslint-plugin-jsx-a11y": "^6.10.2",
158158
"eslint-plugin-prettier": "^5.5.4",
159159
"eslint-plugin-react": "^7.37.5",
160-
"eslint-plugin-react-hooks": "6.0.0-rc.1",
160+
"eslint-plugin-react-hooks": "7.0.0",
161161
"eslint-plugin-simple-import-sort": "^12.1.1",
162162
"http-server": "^14.1.1",
163163
"husky": "^8.0.3",

pnpm-lock.yaml

Lines changed: 15 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/Workshop.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from '@sanity/ui'
99
import {debounce} from 'lodash'
1010
import {isEqual} from 'lodash'
11-
import {memo, useCallback, useEffect, useMemo, useRef, useState} from 'react'
11+
import {memo, startTransition, useCallback, useEffect, useMemo, useRef, useState} from 'react'
1212

1313
import {WorkshopConfig} from './config'
1414
import {DEFAULT_VIEWPORT_VALUE, DEFAULT_ZOOM_VALUE} from './constants'
@@ -137,15 +137,17 @@ export const Workshop = memo(function Workshop(props: WorkshopProps): React.Reac
137137
const prevMediaIndex = mediaIndexRef.current
138138

139139
if (prevMediaIndex < 2 && mediaIndex >= 2) {
140-
setNavigatorExpanded(false)
141-
setInspectorExpanded(false)
140+
startTransition(() => {
141+
setNavigatorExpanded(false)
142+
setInspectorExpanded(false)
143+
})
142144
}
143145

144146
mediaIndexRef.current = mediaIndex
145147
}, [mediaIndex])
146148

147149
useEffect(() => {
148-
setNavigatorExpanded(false)
150+
startTransition(() => setNavigatorExpanded(false))
149151
}, [path])
150152

151153
// Cancel debounced functions

src/core/mount.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {studioTheme, ThemeColorSchemeKey, ThemeProvider, usePrefersDark} from '@sanity/ui'
2-
import {StrictMode, useEffect, useMemo, useState} from 'react'
2+
import {startTransition, StrictMode, useEffect, useMemo, useState} from 'react'
33
import {createRoot} from 'react-dom/client'
44

55
import {WorkshopConfig} from './config'
@@ -29,7 +29,7 @@ function Root(props: {config: WorkshopConfig}) {
2929
const locationStore = useMemo(() => createLocationStore(), [])
3030

3131
useEffect(() => {
32-
setScheme(prefersDark ? 'dark' : 'light')
32+
startTransition(() => setScheme(prefersDark ? 'dark' : 'light'))
3333
}, [prefersDark])
3434

3535
return (

src/core/plugins/props/PropsProvider.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {isEqual} from 'lodash'
2-
import {memo, useCallback, useEffect, useMemo, useRef, useState} from 'react'
2+
import {memo, startTransition, useCallback, useEffect, useMemo, useRef, useState} from 'react'
33

44
import {EMPTY_ARRAY, EMPTY_RECORD} from '../../constants'
55
import {useWorkshop} from '../../useWorkshop'
@@ -90,17 +90,19 @@ export const PropsProvider = memo(function PropsProvider(props: {
9090

9191
encodedValueRef.current = encodedValue
9292

93-
setState((prevState) => {
94-
const nextValue = decodeValue(String(encodedValue)) || {}
95-
if (isEqual(prevState.value, nextValue)) {
96-
return prevState
97-
}
98-
99-
return {
100-
...prevState,
101-
value: nextValue,
102-
}
103-
})
93+
startTransition(() =>
94+
setState((prevState) => {
95+
const nextValue = decodeValue(String(encodedValue)) || {}
96+
if (isEqual(prevState.value, nextValue)) {
97+
return prevState
98+
}
99+
100+
return {
101+
...prevState,
102+
value: nextValue,
103+
}
104+
}),
105+
)
104106
}, [encodedValue])
105107

106108
return <PropsContext.Provider value={ctx}>{children}</PropsContext.Provider>

src/plugin-a11y/useAxeResults.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {useToast} from '@sanity/ui'
22
import axe from 'axe-core'
3-
import {useEffect, useState} from 'react'
3+
import {startTransition, useEffect, useState} from 'react'
44

55
const IGNORE_VIOLATION_IDS = ['landmark-one-main', 'page-has-heading-one']
66

@@ -17,7 +17,7 @@ export function useAxeResults(props: {
1717
if (!enabled) return
1818

1919
try {
20-
setResults(null)
20+
startTransition(() => setResults(null))
2121

2222
axe
2323
.run()

0 commit comments

Comments
 (0)