fix react doctor errors

This commit is contained in:
robert dennis
2026-10-05 23:28:29 -04:00
parent b77251de1d
commit d3410f8543
6 changed files with 27 additions and 21 deletions
@@ -18,7 +18,7 @@
"@tanstack/form-core": "^1.33.0",
"@tanstack/react-form": "^1.33.0",
"@tanstack/react-router": "^1.170.17",
"axios": "^1.18.1",
"axios": "^1.20.0",
"lucide-react": "^1.17.0",
"sonner": "^2.0.7",
"@types/react": "^19.3.0",
+5 -5
View File
@@ -39,7 +39,7 @@
"@tanstack/react-query": "^5",
"@tanstack/react-router": "^1.170.17",
"@tanstack/react-table": "^8.21.3",
"axios": "^1.18.1",
"axios": "^1.20.0",
"boring-avatars": "^1.7.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
@@ -3349,13 +3349,13 @@
"license": "MIT"
},
"node_modules/axios": {
"version": "1.18.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.18.1.tgz",
"integrity": "sha512-3nTvFlvpn9Zu/RkHUqtc7/+al4UpRW5az71ap5zccp6e8RAYEzhMTecX8Dz1wWDYrPpUoB1HAQEGEAEvUr7S9g==",
"version": "1.20.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.20.0.tgz",
"integrity": "sha512-r8aOh8j9cGKpgQAqpzrUHnSIc6a59Y3Xf/cv8sy1DrHCkZHzQGEuoq1tARk6qSyDdtQGSDgpb9kFlruzPvrgwg==",
"license": "MIT",
"dependencies": {
"follow-redirects": "^1.16.0",
"form-data": "^4.0.5",
"form-data": "^4.0.6",
"https-proxy-agent": "^5.0.1",
"proxy-from-env": "^2.1.0"
}
+1 -1
View File
@@ -37,7 +37,7 @@
"@tanstack/react-query": "^5",
"@tanstack/react-router": "^1.170.17",
"@tanstack/react-table": "^8.21.3",
"axios": "^1.18.1",
"axios": "^1.20.0",
"boring-avatars": "^1.7.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
+1 -1
View File
@@ -49,7 +49,7 @@
"@tanstack/form-core": "^1.33.0",
"@tanstack/react-form": "^1.33.0",
"@tanstack/react-router": "^1.170.17",
"axios": "^1.18.1",
"axios": "^1.20.0",
"lucide-react": "^1.17.0",
"sonner": "^2.0.7"
},
@@ -1,4 +1,4 @@
import React, { useRef, useState } from 'react';
import React, { useState } from 'react';
import { ArrowDown, ArrowUp, Plus, X } from 'lucide-react';
import type { AdminExtensionSettingField, AdminExtensionSettingValue } from '@/api/admin/extensions/queries';
import Button from '@/components/elements/Button';
@@ -36,6 +36,13 @@ const asItems = (value: SettingValue): string[] => (Array.isArray(value) ? value
const asChoices = (value: SettingValue): Array<string | number> => (Array.isArray(value) ? value : []);
// Row keys continue past the largest existing key so a reset or append never reuses a mounted row.
const freshKeys = (existing: number[], count: number): number[] => {
const start = existing.length > 0 ? Math.max(...existing) + 1 : 0;
return Array.from({ length: count }, (_, i) => start + i);
};
export const pickerColor = (value: string): string | null => {
if (!hexColor.test(value)) {
return null;
@@ -139,9 +146,8 @@ function RowButton({
function ListControl({ field, value, onChange }: ControlProps) {
const items = asItems(value);
const maxItems = field.constraints?.max_items ?? undefined;
const nextKey = useRef(0);
const [keys, setKeys] = useState<number[]>([]);
const rowKeys = keys.length === items.length ? keys : items.map(() => nextKey.current++);
const rowKeys = keys.length === items.length ? keys : freshKeys(keys, items.length);
if (rowKeys !== keys) {
setKeys(rowKeys);
}
@@ -163,7 +169,7 @@ function ListControl({ field, value, onChange }: ControlProps) {
onChange(swap(items, index, offset));
};
const add = () => {
setKeys([...rowKeys, nextKey.current++]);
setKeys([...rowKeys, ...freshKeys(rowKeys, 1)]);
onChange([...items, '']);
};
@@ -1,6 +1,6 @@
/** @vitest-environment jsdom */
import type React from 'react';
import { createRef, useImperativeHandle, type FocusEventHandler, type Ref } from 'react';
import { act, cleanup, fireEvent, render, screen } from '@testing-library/react';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { useAppForm, type AppForm } from '@/components/form';
@@ -10,14 +10,14 @@ afterEach(cleanup);
type Values = { name: string; memory: number | null };
function Harness({
onForm,
formRef,
onNameBlur,
}: {
onForm: (form: AppForm<Values>) => void;
onNameBlur?: React.FocusEventHandler<HTMLInputElement>;
formRef: Ref<AppForm<Values>>;
onNameBlur?: FocusEventHandler<HTMLInputElement>;
}) {
const form = useAppForm({ defaultValues: { name: '', memory: 512 } as Values });
onForm(form);
useImperativeHandle(formRef, () => form, [form]);
return (
<>
@@ -39,11 +39,11 @@ function Harness({
);
}
const renderHarness = (onNameBlur?: React.FocusEventHandler<HTMLInputElement>) => {
let form: AppForm<Values> | undefined;
render(<Harness onForm={(value) => (form = value)} onNameBlur={onNameBlur} />);
const renderHarness = (onNameBlur?: FocusEventHandler<HTMLInputElement>) => {
const formRef = createRef<AppForm<Values>>();
render(<Harness formRef={formRef} onNameBlur={onNameBlur} />);
return () => form!;
return () => formRef.current!;
};
describe('form fields', () => {