Skip to content

Commit b5c6f22

Browse files
authored
Fix mounting behaviour (#81)
Co-authored-by: Alex Nicholson <alex.n@clove.kitchen>
1 parent 6d086ed commit b5c6f22

3 files changed

Lines changed: 7 additions & 1 deletion

File tree

packages/react-dialog-async/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "react-dialog-async",
33
"description": "A promise-based way to show dialogs in React",
44
"type": "module",
5-
"version": "2.1.0",
5+
"version": "2.1.1",
66
"sideEffects": false,
77
"main": "index.js",
88
"module": "index.esm.js",

packages/react-dialog-async/src/DialogProvider/DialogProvider.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ const DialogProvider = ({
9696
const show = useCallback(
9797
(id: string, data: unknown, unmountDelay?: number): Promise<unknown> => {
9898
return new Promise((resolve) => {
99+
if (unmountDelayTimeoutRefs.current[id] !== undefined) {
100+
clearTimeout(unmountDelayTimeoutRefs.current[id]);
101+
}
102+
99103
setDialogState((state) => ({
100104
...state,
101105
[id]: {
@@ -167,6 +171,7 @@ const DialogProvider = ({
167171
key={id}
168172
open={open}
169173
data={data}
174+
mounted={true} // Dialog is always mounted when it's being rendered
170175
handleClose={(value) => {
171176
resolve?.(value);
172177
hide(id);

packages/react-dialog-async/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ComponentType } from 'react';
22

33
export interface AsyncDialogProps<Request = void, Response = undefined> {
44
open: boolean;
5+
mounted: boolean;
56
handleClose: (data?: Response) => void;
67
data: Request;
78
}

0 commit comments

Comments
 (0)