修复: 08-07-business-routing-regression-repair 关闭资产创建跳转回归
这个提交包含在:
@@ -21,6 +21,7 @@ type GuardRegistration = {
|
||||
type UnsavedChangesContextValue = {
|
||||
register: (id: string, registration: GuardRegistration | null) => void;
|
||||
runGuarded: (action: () => void) => void;
|
||||
runAfterSuccessfulSave: (action: () => void) => void;
|
||||
};
|
||||
|
||||
const UnsavedChangesContext = createContext<UnsavedChangesContextValue | null>(null);
|
||||
@@ -76,6 +77,17 @@ export function UnsavedChangesProvider({ children }: PropsWithChildren) {
|
||||
setDialogOpen(true);
|
||||
}, []);
|
||||
|
||||
const runWithNextNavigationAllowed = useCallback((action: () => void) => {
|
||||
allowNextNavigationRef.current = true;
|
||||
try {
|
||||
action();
|
||||
} finally {
|
||||
queueMicrotask(() => {
|
||||
allowNextNavigationRef.current = false;
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (blocker.state === "blocked") {
|
||||
setDialogOpen(true);
|
||||
@@ -95,7 +107,10 @@ export function UnsavedChangesProvider({ children }: PropsWithChildren) {
|
||||
};
|
||||
}, []);
|
||||
|
||||
const value = useMemo(() => ({ register, runGuarded }), [register, runGuarded]);
|
||||
const value = useMemo(
|
||||
() => ({ register, runGuarded, runAfterSuccessfulSave: runWithNextNavigationAllowed }),
|
||||
[register, runGuarded, runWithNextNavigationAllowed],
|
||||
);
|
||||
|
||||
return (
|
||||
<UnsavedChangesContext.Provider value={value}>
|
||||
@@ -129,14 +144,7 @@ export function UnsavedChangesProvider({ children }: PropsWithChildren) {
|
||||
return;
|
||||
}
|
||||
if (!action) return;
|
||||
allowNextNavigationRef.current = true;
|
||||
try {
|
||||
action();
|
||||
} finally {
|
||||
queueMicrotask(() => {
|
||||
allowNextNavigationRef.current = false;
|
||||
});
|
||||
}
|
||||
runWithNextNavigationAllowed(action);
|
||||
}}
|
||||
/>
|
||||
</UnsavedChangesContext.Provider>
|
||||
@@ -157,3 +165,12 @@ export function useUnsavedChangesGuard(dirty: boolean, label: string) {
|
||||
|
||||
return context.runGuarded;
|
||||
}
|
||||
|
||||
export function usePostSaveNavigation() {
|
||||
const context = useContext(UnsavedChangesContext);
|
||||
if (!context) {
|
||||
throw new Error("usePostSaveNavigation 必须在 UnsavedChangesProvider 内使用");
|
||||
}
|
||||
|
||||
return context.runAfterSuccessfulSave;
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户