Skip to content

Commit 4340868

Browse files
authored
Merge pull request #211 from Zac-HD/react-compiler
Use `react-compiler` rc2
2 parents 2f007a8 + 29e4712 commit 4340868

File tree

18 files changed

+724
-592
lines changed

18 files changed

+724
-592
lines changed

src/hypofuzz/frontend/eslint.config.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export default [{
1818
"simple-import-sort/imports": "error",
1919
"simple-import-sort/exports": "error",
2020
"react-hooks/rules-of-hooks": "error",
21-
"react-hooks/exhaustive-deps": "error",
21+
'react-hooks/react-compiler': 'error',
22+
// false positives with react compiler.
23+
// see https://github.com/reactwg/react-compiler/discussions/18
24+
// "react-hooks/exhaustive-deps": "error",
2225
},
2326
}];

src/hypofuzz/frontend/package-lock.json

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

src/hypofuzz/frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
"@types/react-router-dom": "^5.3.3",
3131
"@typescript-eslint/parser": "^8.34.0",
3232
"@vitejs/plugin-react": "^4.2.1",
33+
"babel-plugin-react-compiler": "^19.1.0-rc.2",
3334
"eslint": "^9.28.0",
34-
"eslint-plugin-react-hooks": "^5.1.0",
35+
"eslint-plugin-react-hooks": "^6.0.0-rc.1",
3536
"eslint-plugin-simple-import-sort": "^12.1.1",
3637
"prettier": "^3.2.5",
3738
"sass": "^1.84.0",

src/hypofuzz/frontend/src/components/RangeSlider.tsx

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useEffect, useRef, useState } from "react"
1+
import { useEffect, useRef, useState } from "react"
22

33
interface RangeSliderProps {
44
min: number
@@ -24,47 +24,41 @@ export function RangeSlider({ min, max, value, onChange, step = 1 }: RangeSlider
2424
const zIndexMin = minPercent < 50 ? 1 : 2
2525
const zIndexMax = maxPercent < 50 ? 2 : 1
2626

27-
const getValueFromPosition = useCallback(
28-
(clientX: number): number => {
29-
if (!sliderRef.current) return min
30-
31-
const rect = sliderRef.current.getBoundingClientRect()
32-
const percent = Math.max(
33-
0,
34-
Math.min(100, ((clientX - rect.left) / rect.width) * 100),
35-
)
36-
const rawValue = min + (percent / 100) * range
37-
38-
// Snap to step
39-
const steppedValue = Math.round(rawValue / step) * step
40-
return Math.max(min, Math.min(max, steppedValue))
41-
},
42-
[min, max, range, step],
43-
)
27+
const getValueFromPosition = (clientX: number): number => {
28+
if (!sliderRef.current) return min
29+
30+
const rect = sliderRef.current.getBoundingClientRect()
31+
const percent = Math.max(
32+
0,
33+
Math.min(100, ((clientX - rect.left) / rect.width) * 100),
34+
)
35+
const rawValue = min + (percent / 100) * range
36+
37+
// Snap to step
38+
const steppedValue = Math.round(rawValue / step) * step
39+
return Math.max(min, Math.min(max, steppedValue))
40+
}
4441

4542
const handleMouseDown = (thumb: "min" | "max") => (event: React.MouseEvent) => {
4643
event.preventDefault()
4744
setDragging(thumb)
4845
}
4946

50-
const handleMouseMove = useCallback(
51-
(event: MouseEvent) => {
52-
if (!dragging) return
47+
const handleMouseMove = (event: MouseEvent) => {
48+
if (!dragging) return
5349

54-
const newValue = getValueFromPosition(event.clientX)
50+
const newValue = getValueFromPosition(event.clientX)
5551

56-
if (dragging === "min") {
57-
onChange([Math.min(newValue, maxValue), maxValue])
58-
} else {
59-
onChange([minValue, Math.max(newValue, minValue)])
60-
}
61-
},
62-
[dragging, getValueFromPosition, minValue, maxValue, onChange],
63-
)
52+
if (dragging === "min") {
53+
onChange([Math.min(newValue, maxValue), maxValue])
54+
} else {
55+
onChange([minValue, Math.max(newValue, minValue)])
56+
}
57+
}
6458

65-
const handleMouseUp = useCallback(() => {
59+
const handleMouseUp = () => {
6660
setDragging(null)
67-
}, [])
61+
}
6862

6963
const handleTrackClick = (event: React.MouseEvent) => {
7064
if (dragging) return

src/hypofuzz/frontend/src/components/Table.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { faArrowDown, faArrowUp, faTimes } from "@fortawesome/free-solid-svg-icons"
22
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
3-
import React, { ReactNode, useMemo, useState } from "react"
3+
import React, { ReactNode, useState } from "react"
44
import { useIsMobile } from "src/hooks/useIsMobile"
55

66
interface TableHeader<T> {
@@ -38,7 +38,7 @@ export function Table<T>({
3838
const [filterString, setFilterString] = useState("")
3939
const isMobile = useIsMobile()
4040

41-
const displayData = useMemo(() => {
41+
function getDisplayData() {
4242
let displayData = data
4343

4444
if (filterString) {
@@ -58,7 +58,7 @@ export function Table<T>({
5858

5959
const sorted = [...displayData].sortKey(item => headers[sortColumn].sortKey!(item))
6060
return sortDirection === SortOrder.ASC ? sorted : sorted.reverse()
61-
}, [data, sortColumn, sortDirection, headers, filterString, filterStrings])
61+
}
6262

6363
const handleHeaderClick = (index: number) => {
6464
if (!headers[index].sortKey) return
@@ -78,6 +78,8 @@ export function Table<T>({
7878
onFilterChange?.(filter)
7979
}
8080

81+
const displayData = getDisplayData()
82+
8183
return (
8284
<div className="table">
8385
{/* only show filter box if some rows are filterable */}

0 commit comments

Comments
 (0)