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