Skip to content

Commit 3b5beed

Browse files
committed
fix: use react compiler
1 parent da5943d commit 3b5beed

File tree

7 files changed

+52
-34
lines changed

7 files changed

+52
-34
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ module.exports = {
9090
'react/prop-types': 'off',
9191
'react-hooks/exhaustive-deps': 'error', // Checks effect dependencies
9292
'react-hooks/rules-of-hooks': 'error', // Checks rules of Hooks
93-
'react-compiler/react-compiler': 'warn', // Set to error once existing warnings are fixed
93+
'react-compiler/react-compiler': 'error',
9494
'react/no-unescaped-entities': 'off',
9595
'no-restricted-imports': [
9696
'error',

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- run: pnpm install
3939
- name: Register Problem Matcher for ESLint that handles -f compact and shows warnings and errors inline on PRs
4040
run: echo "::add-matcher::.github/eslint-compact.json"
41-
- run: "pnpm lint -f compact --rule 'no-warning-comments: [off]' --max-warnings 12"
41+
- run: "pnpm lint -f compact --rule 'no-warning-comments: [off]' --max-warnings 0"
4242

4343
test:
4444
needs: [build]

.storybook/main.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ const config: StorybookConfig = {
2525
return mergeConfig(config, {
2626
plugins: [
2727
viteReact({
28-
babel: {plugins: [['babel-plugin-react-compiler', {target: '18'}]]},
28+
babel: {
29+
plugins: [['babel-plugin-react-compiler', {target: '18'}]],
30+
},
2931
}),
3032
tsconfigPaths(),
3133
],

package.config.ts

+18
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,22 @@ export default defineConfig({
1414
noImplicitBrowsersList: 'off',
1515
},
1616
tsconfig: 'tsconfig.dist.json',
17+
babel: {reactCompiler: true},
18+
reactCompilerOptions: {
19+
target: '18',
20+
logger: {
21+
logEvent(filename, event) {
22+
if (event.kind === 'CompileError') {
23+
console.group(`[${filename}] ${event.kind}`)
24+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
25+
const {reason, description, severity, loc, suggestions} = event.detail as any
26+
console.error(`[${severity}] ${reason}`)
27+
console.log(`${filename}:${loc.start?.line}:${loc.start?.column} ${description}`)
28+
console.log(suggestions)
29+
30+
console.groupEnd()
31+
}
32+
},
33+
},
34+
},
1735
})

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sanity/ui",
3-
"version": "2.8.12",
3+
"version": "2.8.13-canary.1",
44
"keywords": [
55
"sanity",
66
"ui",
@@ -110,6 +110,7 @@
110110
"@sanity/icons": "^3.4.0",
111111
"csstype": "^3.1.3",
112112
"framer-motion": "11.0.8",
113+
"react-compiler-runtime": "19.0.0-beta-6fc168f-20241025",
113114
"react-refractor": "^2.2.0",
114115
"use-effect-event": "^1.0.2"
115116
},

pnpm-lock.yaml

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/components/menu/useMenuController.ts

+18-21
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,28 @@ export function useMenuController(props: {
3636
activeIndexRef.current = nextActiveIndex
3737
}, [])
3838

39-
const mount = useCallback(
40-
(element: HTMLElement | null, selected?: boolean): (() => void) => {
41-
if (!element) return () => undefined
39+
const mount = (element: HTMLElement | null, selected?: boolean): (() => void) => {
40+
if (!element) return () => undefined
4241

43-
if (elementsRef.current.indexOf(element) === -1) {
44-
elementsRef.current.push(element)
45-
_sortElements(rootElementRef.current, elementsRef.current)
46-
}
42+
if (elementsRef.current.indexOf(element) === -1) {
43+
elementsRef.current.push(element)
44+
_sortElements(rootElementRef.current, elementsRef.current)
45+
}
4746

48-
if (selected) {
49-
const selectedIndex = elementsRef.current.indexOf(element)
47+
if (selected) {
48+
const selectedIndex = elementsRef.current.indexOf(element)
5049

51-
setActiveIndex(selectedIndex)
52-
}
50+
setActiveIndex(selectedIndex)
51+
}
5352

54-
return () => {
55-
const idx = elementsRef.current.indexOf(element)
53+
return () => {
54+
const idx = elementsRef.current.indexOf(element)
5655

57-
if (idx > -1) {
58-
elementsRef.current.splice(idx, 1)
59-
}
56+
if (idx > -1) {
57+
elementsRef.current.splice(idx, 1)
6058
}
61-
},
62-
[rootElementRef, setActiveIndex],
63-
)
59+
}
60+
}
6461

6562
const handleKeyDown = useCallback(
6663
(event: React.KeyboardEvent<HTMLDivElement>) => {
@@ -170,15 +167,15 @@ export function useMenuController(props: {
170167
[setActiveIndex],
171168
)
172169

173-
const handleItemMouseLeave = useCallback(() => {
170+
const handleItemMouseLeave = () => {
174171
// Set the active index to -2 to deactivate all menu items
175172
// when the user moves the mouse away from the menu item.
176173
// We avoid using -1 because it would focus the first menu item,
177174
// which would be incorrect when the user hovers over a gap
178175
// between two menu items or a menu divider.
179176
setActiveIndex(-2)
180177
rootElementRef.current?.focus()
181-
}, [rootElementRef, setActiveIndex])
178+
}
182179

183180
// Set focus on the currently active element
184181
useEffect(() => {

0 commit comments

Comments
 (0)