chore(eslint): add eslint-plugin-react-compiler (#5918)

* chore(eslint): add `eslint-plugin-react-compiler`

* refactor: fix eslint warnings and avoid in-render mutations

---------

Co-authored-by: Slinetrac <realakayuki@gmail.com>
This commit is contained in:
Sukka
2025-12-22 12:51:20 +08:00
committed by GitHub
co-authored by Slinetrac
parent eafa08066d
commit 8e48e4ed10
8 changed files with 100 additions and 55 deletions
+2 -2
View File
@@ -12,7 +12,7 @@ import { useTranslation } from "react-i18next";
import matchCaseIcon from "@/assets/image/component/match_case.svg?react";
import matchWholeWordIcon from "@/assets/image/component/match_whole_word.svg?react";
import useRegularExpressionIcon from "@/assets/image/component/use_regular_expression.svg?react";
import UseRegularExpressionIcon from "@/assets/image/component/use_regular_expression.svg?react";
import { buildRegex, compileStringMatcher } from "@/utils/search-matcher";
export type SearchState = {
@@ -223,7 +223,7 @@ export const BaseSearchBox = ({
<Tooltip title={t("shared.placeholders.useRegex")}>
<div>
<SvgIcon
component={useRegularExpressionIcon}
component={UseRegularExpressionIcon}
aria-label={useRegularExpression ? "active" : "inactive"}
{...iconStyle}
onClick={handleToggleUseRegularExpression}
+17 -18
View File
@@ -123,24 +123,6 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
useEffect(() => {
initialDataRef.current = initialData;
}, [initialData]);
// Background refresh: when the dialog/model is ready and the underlying resource key changes,
// try to refresh content (only if user hasn't typed). Do NOT depend on `initialData` function
// identity because callers often pass inline lambdas that change every render.
useEffect(() => {
if (!open) return;
// Only attempt after initial model is ready to avoid racing the initial load
if (!modelPath) return;
// Avoid immediate double-load on open: the initial load has just completed.
if (skipNextRefreshRef.current) {
skipNextRefreshRef.current = false;
return;
}
// Only meaningful when a callable loader is provided (plain Promise cannot be "recalled")
if (typeof initialDataRef.current === "function") {
void reloadLatest();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [open, modelPath, dataKey]);
// Helper to (soft) reload latest source and apply only if the user hasn't typed yet
const reloadLatest = useLockFn(async () => {
// Snapshot the model/doc identity and bump a token so older calls can't win
@@ -201,6 +183,23 @@ export const EditorViewer = <T extends Language>(props: Props<T>) => {
}
}
});
// Background refresh: when the dialog/model is ready and the underlying resource key changes,
// try to refresh content (only if user hasn't typed). Do NOT depend on `initialData` function
// identity because callers often pass inline lambdas that change every render.
useEffect(() => {
if (!open) return;
// Only attempt after initial model is ready to avoid racing the initial load
if (!modelPath) return;
// Avoid immediate double-load on open: the initial load has just completed.
if (skipNextRefreshRef.current) {
skipNextRefreshRef.current = false;
return;
}
// Only meaningful when a callable loader is provided (plain Promise cannot be "recalled")
if (typeof initialDataRef.current === "function") {
void reloadLatest();
}
}, [open, modelPath, dataKey, reloadLatest]);
const beforeMount = () => {
monacoInitialization();
+11 -11
View File
@@ -88,10 +88,6 @@ export function ProfileViewer({ onChange, ref }: ProfileViewerProps) {
const handleOk = useLockFn(
handleSubmit(async (form) => {
if (form.option?.timeout_seconds) {
form.option.timeout_seconds = +form.option.timeout_seconds;
}
setLoading(true);
try {
// 基本验证
@@ -101,17 +97,21 @@ export function ProfileViewer({ onChange, ref }: ProfileViewerProps) {
}
// 处理表单数据
if (form.option?.update_interval) {
form.option.update_interval = +form.option.update_interval;
} else {
delete form.option?.update_interval;
const option = form.option ? { ...form.option } : undefined;
if (option?.timeout_seconds) {
option.timeout_seconds = +option.timeout_seconds;
}
if (form.option?.user_agent === "") {
delete form.option.user_agent;
if (option?.update_interval) {
option.update_interval = +option.update_interval;
} else if (option) {
option.update_interval = undefined;
}
if (option?.user_agent === "") {
option.user_agent = undefined;
}
const name = form.name || `${form.type} file`;
const item = { ...form, name };
const item = { ...form, name, option };
const isRemote = form.type === "remote";
const isUpdate = openType === "edit";
+10 -16
View File
@@ -88,25 +88,19 @@ export const WebUIItem = (props: Props) => {
);
}
const placeholderCounts: Record<string, number> = {};
let textCounter = 0;
const renderedParts = highlightedParts.map((part) => {
const renderedParts = highlightedParts.map((part, index) => {
const isPlaceholder =
part === "%host" || part === "%port" || part === "%secret";
const repeatIndex = highlightedParts
.slice(0, index)
.filter((prev) => prev === part).length;
const key = `${part || "empty"}-${repeatIndex}`;
if (isPlaceholder) {
const count = placeholderCounts[part] ?? 0;
placeholderCounts[part] = count + 1;
return (
<span key={`placeholder-${part}-${count}`} className="placeholder">
{part}
</span>
);
}
const key = `text-${textCounter}-${part || "empty"}`;
textCounter += 1;
return <span key={key}>{part}</span>;
return (
<span key={key} className={isPlaceholder ? "placeholder" : undefined}>
{part}
</span>
);
});
return (