Skip to content

Commit 4cd4d36

Browse files
committed
fix: Proper async handling for portals
1 parent 54c5ad9 commit 4cd4d36

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/internal/portal/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ function manageDefaultContainer(setState: React.Dispatch<React.SetStateAction<El
2323
}
2424

2525
function manageAsyncContainer(
26-
getContainer: () => Promise<HTMLElement>,
26+
getContainer: (options: { abortSignal: AbortSignal }) => Promise<HTMLElement>,
2727
removeContainer: (container: HTMLElement) => void,
2828
setState: React.Dispatch<React.SetStateAction<Element | null>>
2929
) {
3030
let newContainer: HTMLElement;
31-
getContainer().then(
31+
const abortController = new AbortController();
32+
getContainer({ abortSignal: abortController.signal }).then(
3233
container => {
3334
newContainer = container;
3435
setState(container);
@@ -38,6 +39,7 @@ function manageAsyncContainer(
3839
}
3940
);
4041
return () => {
42+
abortController.abort();
4143
removeContainer(newContainer);
4244
};
4345
}

0 commit comments

Comments
 (0)