From 317060300d786e9fda590d8d9dd3830bb5423148 Mon Sep 17 00:00:00 2001 From: ClarkXia Date: Tue, 8 Oct 2024 11:27:19 +0800 Subject: [PATCH] fix: avoid infinite setOutlets loop when config keepAlivePaths (#6995) --- .changeset/happy-cars-punch.md | 5 +++++ packages/runtime/src/KeepAliveOutlet.tsx | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .changeset/happy-cars-punch.md diff --git a/.changeset/happy-cars-punch.md b/.changeset/happy-cars-punch.md new file mode 100644 index 0000000000..7d9681918c --- /dev/null +++ b/.changeset/happy-cars-punch.md @@ -0,0 +1,5 @@ +--- +'@ice/runtime': patch +--- + +fix: avoid infinite setOutlets loop when config keepAlivePaths diff --git a/packages/runtime/src/KeepAliveOutlet.tsx b/packages/runtime/src/KeepAliveOutlet.tsx index 8c4a667f83..7bf8057881 100644 --- a/packages/runtime/src/KeepAliveOutlet.tsx +++ b/packages/runtime/src/KeepAliveOutlet.tsx @@ -41,10 +41,11 @@ export default function KeepAliveOutlet(props: OutletProps) { if (outlets.length !== 0 || outletRef.current?.pathname !== location.pathname) { let currentOutlets = outletRef.current ? [outletRef.current] : outlets; + // Check current path if exsist before filter, to avoid infinite setOutlets loop. + const result = currentOutlets.some(o => o.pathname === location.pathname); if (keepAlivePaths && keepAlivePaths.length > 0) { currentOutlets = currentOutlets.filter(o => keepAlivePaths.includes(o.pathname)); } - const result = currentOutlets.some(o => o.pathname === location.pathname); if (!result) { setOutlets([ ...currentOutlets,