shlomiassaf / ngx-modialog

Modal / Dialog for Angular
http://shlomiassaf.github.io/ngx-modialog
MIT License
686 stars 242 forks source link

Dialog destroy (for instance through Webpack HMR) gives exception #395

Open Mysame opened 7 years ago

Mysame commented 7 years ago

Webpack's Hot Module Replacement (HMR) destroys the current app and inserts a new one. Upon destroying with an ngx-modialog open, an exception is thrown.

As a result, the dialog is never fully cleaned up. Even if an error prevents the dialog from opening, a refresh after this happens will still cause the gui to be blocked by what I can only imagine is the "dialog still being open" somewhere.

The destroy code:

    module.hot.dispose(() => {
        // Before restarting the app, we create a new root element and dispose the old one
        const oldRootElem = document.querySelector("app");
        const newRootElem = document.createElement("app");

        oldRootElem!.parentNode!.insertBefore(newRootElem, oldRootElem);

        if (modulePromise) {
            modulePromise.then(appModule => {
                appModule.destroy();
            });
        }

        oldRootElem.parentNode.removeChild(oldRootElem);
    });
Unhandled Promise rejection: Dialog was forced to close by an unknown source. ; Zone: <root> ; Task: Promise.then ; Value: Error: Dialog was forced to close by an unknown source.
    at new DialogBailOutError (ngx-modialog.es5.js:376)
    at DialogRef.bailOut (ngx-modialog.es5.js:465)
    at ModalOverlay.ngOnDestroy (ngx-modialog.es5.js:1133)
    at callProviderLifecycles (core.es5.js:11200)
    at callElementProvidersLifecycles (core.es5.js:11169)
    at callLifecycleHooksChildrenFirst (core.es5.js:11153)
    at destroyView (core.es5.js:12494)
    at callWithDebugContext (core.es5.js:13475)
    at Object.debugDestroyView [as destroyView] (core.es5.js:13029)
    at ViewRef_.destroy (core.es5.js:10214) Error: Dialog was forced to close by an unknown source.
    at new DialogBailOutError (http://localhost:60688/dist/main-client.js?v=LI6_ZEsC7rS7Qa8upYS0rB8vadPU0ngE77oKN9WPMbo:35582:28)
    at DialogRef.bailOut (http://localhost:60688/dist/main-client.js?v=LI6_ZEsC7rS7Qa8upYS0rB8vadPU0ngE77oKN9WPMbo:35671:41)
    at ModalOverlay.ngOnDestroy (http://localhost:60688/dist/main-client.js?v=LI6_ZEsC7rS7Qa8upYS0rB8vadPU0ngE77oKN9WPMbo:36339:28)
    at callProviderLifecycles (http://localhost:60688/dist/main-client.js?v=LI6_ZEsC7rS7Qa8upYS0rB8vadPU0ngE77oKN9WPMbo:12118:18)
    at callElementProvidersLifecycles (http://localhost:60688/dist/main-client.js?v=LI6_ZEsC7rS7Qa8upYS0rB8vadPU0ngE77oKN9WPMbo:12087:13)
    at callLifecycleHooksChildrenFirst (http://localhost:60688/dist/main-client.js?v=LI6_ZEsC7rS7Qa8upYS0rB8vadPU0ngE77oKN9WPMbo:12071:17)
    at destroyView (http://localhost:60688/dist/main-client.js?v=LI6_ZEsC7rS7Qa8upYS0rB8vadPU0ngE77oKN9WPMbo:13412:5)
    at callWithDebugContext (http://localhost:60688/dist/main-client.js?v=LI6_ZEsC7rS7Qa8upYS0rB8vadPU0ngE77oKN9WPMbo:14393:42)
    at Object.debugDestroyView [as destroyView] (http://localhost:60688/dist/main-client.js?v=LI6_ZEsC7rS7Qa8upYS0rB8vadPU0ngE77oKN9WPMbo:13947:12)
    at ViewRef_.destroy (http://localhost:60688/dist/main-client.js?v=LI6_ZEsC7rS7Qa8upYS0rB8vadPU0ngE77oKN9WPMbo:11132:18)