diff --git a/web/web-lock.js b/web/web-lock.js --- a/web/web-lock.js +++ b/web/web-lock.js @@ -94,6 +94,17 @@ return lockStatuses.ACQUIRED; }, [lockRequest, isVisible]); + React.useEffect(() => { + if (!import.meta.webpackHot) { + return undefined; + } + const webpackHot: WebpackHot = (import.meta.webpackHot: any); + webpackHot.dispose(releaseLockOrAbortRequest); + return () => { + webpackHot.removeDisposeHandler(releaseLockOrAbortRequest); + }; + }, [releaseLockOrAbortRequest]); + return { lockStatus, releaseLockOrAbortRequest }; } @@ -127,4 +138,9 @@ type LockMode = 'exclusive' | 'shared'; +type WebpackHot = { + +dispose: ((data: mixed) => void) => void, + +removeDisposeHandler: ((data: mixed) => void) => void, +}; + export { useWebLock };