diff --git a/packages/antd/src/providers/notificationProvider/index.tsx b/packages/antd/src/providers/notificationProvider/index.tsx index 9d77c91325344..74c4a3e12d270 100644 --- a/packages/antd/src/providers/notificationProvider/index.tsx +++ b/packages/antd/src/providers/notificationProvider/index.tsx @@ -39,12 +39,21 @@ export const useNotificationProvider = (): NotificationProvider => { closeIcon: <>, }); } else { - notification.open({ + const config = { key, description: message, message: description ?? null, - type, - }); + }; + const method = + type && type !== "progress" + ? notification[type as "success" | "error" | "warning" | "info"] + : notification.open; + + if (typeof method === "function") { + method(config); + } else { + notification.open(config); + } } }, close: (key) => notification.destroy(key), diff --git a/packages/cli/package.json b/packages/cli/package.json index 86fc8533bad5b..35faaef116acc 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -68,7 +68,6 @@ "prettier": "^2.7.1", "semver": "7.5.2", "semver-diff": "^3.1.1", - "temp": "^0.9.4", "tslib": "^2.6.2" }, "devDependencies": { @@ -90,7 +89,6 @@ "@types/pluralize": "^0.0.29", "@types/prettier": "^2.7.3", "@types/semver": "^7.5.8", - "@types/temp": "^0.9.1", "@vitest/ui": "^2.1.8", "tsup": "^6.7.0", "typescript": "^5.8.3", diff --git a/packages/cli/src/commands/add/sub-commands/resource/create-resources.ts b/packages/cli/src/commands/add/sub-commands/resource/create-resources.ts index da38518b9d933..87e24ac6c6ed0 100644 --- a/packages/cli/src/commands/add/sub-commands/resource/create-resources.ts +++ b/packages/cli/src/commands/add/sub-commands/resource/create-resources.ts @@ -16,8 +16,9 @@ import { import inquirer from "inquirer"; import { join } from "path"; import { plural } from "pluralize"; -import temp from "temp"; import { getCommandRootDir } from "./get-command-root-dir"; +import { mkdtempSync } from "fs"; +import { tmpdir } from "os"; export const defaultActions = ["list", "create", "edit", "show"]; @@ -134,9 +135,6 @@ export const createResources = async ( } moveSync(tempDir, destinationResourcePath, moveSyncOptions); - // clear temp dir - temp.cleanupSync(); - // if use Next.js, generate page files. This makes easier to use the resource if (isNextJs) { generateNextJsPages( @@ -182,8 +180,7 @@ export const createResources = async ( }; const generateTempDir = (): string => { - temp.track(); - return temp.mkdirSync("resource"); + return mkdtempSync(join(tmpdir(), "resource-")); }; /** diff --git a/packages/react-hook-form/src/useForm/index.ts b/packages/react-hook-form/src/useForm/index.ts index 99946820a02b6..7f938651925b0 100644 --- a/packages/react-hook-form/src/useForm/index.ts +++ b/packages/react-hook-form/src/useForm/index.ts @@ -129,6 +129,7 @@ export const useForm = < watch, setValue, getValues, + reset, handleSubmit: handleSubmitReactHookForm, setError, formState: { dirtyFields }, @@ -253,39 +254,28 @@ export const useForm = < }); }; - // On query load, attempt a first sync after registration effects run. + // On query load, reset the form with server data natively. + // This ensures useFieldArray and other RHF internals are properly initialized. + const initialLoadRef = React.useRef(true); useEffect(() => { const data = query?.data?.data; if (!data) { queryDataRef.current = undefined; syncedFieldsRef.current = new Set(); mountedFieldsRef.current = new Set(); + initialLoadRef.current = true; return; } - let isActive = true; - - const applyQueryValues = () => { - if (!isActive) return; - - applyValuesToFields(getRegisteredFields(), data, false); - }; - queryDataRef.current = data; - syncedFieldsRef.current = new Set(); mountedFieldsRef.current = getMountedFields(); - // defer until after field registration effects - if (typeof queueMicrotask === "function") { - queueMicrotask(applyQueryValues); - } else { - Promise.resolve().then(applyQueryValues); + if (initialLoadRef.current) { + initialLoadRef.current = false; + syncedFieldsRef.current = new Set(); + reset(data as unknown as TVariables, { keepDirtyValues: true }); } - - return () => { - isActive = false; - }; - }, [query?.data, setValue, getValues]); + }, [query?.data, reset, getValues]); // Re-sync when new fields register; do not override user edits. useEffect(() => {