Skip to content

Commit

Permalink
fix: avoid infinite setOutlets loop when config keepAlivePaths (#6995)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClarkXia authored Oct 8, 2024
1 parent f50fe55 commit 3170603
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/happy-cars-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ice/runtime': patch
---

fix: avoid infinite setOutlets loop when config keepAlivePaths
3 changes: 2 additions & 1 deletion packages/runtime/src/KeepAliveOutlet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3170603

Please sign in to comment.