From 782c514aac301e0b1708dfd1912f8c21dc35733e Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Thu, 9 Sep 2021 20:17:42 +0300 Subject: [PATCH 1/3] fix: close overlay on disconnection --- client-src/index.js | 12 +- .../overlay.test.js.snap.webpack4 | 194 ++++++++++++------ .../overlay.test.js.snap.webpack5 | 170 ++++++++++----- test/e2e/overlay.test.js | 75 +++++-- 4 files changed, 320 insertions(+), 131 deletions(-) diff --git a/client-src/index.js b/client-src/index.js index 5dd697e983..63251d7992 100644 --- a/client-src/index.js +++ b/client-src/index.js @@ -161,12 +161,12 @@ const onSocketMessage = { log.warn(strippedWarnings[i]); } - const needShowOverlay = + const needShowOverlayForWarnings = typeof options.overlay === "boolean" ? options.overlay : options.overlay && options.overlay.warnings; - if (needShowOverlay) { + if (needShowOverlayForWarnings) { show(warnings, "warnings"); } @@ -185,12 +185,12 @@ const onSocketMessage = { log.error(strippedErrors[i]); } - const needShowOverlay = + const needShowOverlayForErrors = typeof options.overlay === "boolean" ? options.overlay : options.overlay && options.overlay.errors; - if (needShowOverlay) { + if (needShowOverlayForErrors) { show(errors, "errors"); } }, @@ -200,6 +200,10 @@ const onSocketMessage = { close() { log.info("Disconnected!"); + if (options.overlay) { + hide(); + } + sendMessage("Close"); }, }; diff --git a/test/e2e/__snapshots__/overlay.test.js.snap.webpack4 b/test/e2e/__snapshots__/overlay.test.js.snap.webpack4 index 804589bc46..b92f1d39db 100644 --- a/test/e2e/__snapshots__/overlay.test.js.snap.webpack4 +++ b/test/e2e/__snapshots__/overlay.test.js.snap.webpack4 @@ -1,5 +1,33 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`overlay should not show a warning when "client.overlay" is "false": page html 1`] = ` +" + + +" +`; + +exports[`overlay should not show a warning when "client.overlay.warnings" is "false": page html 1`] = ` +" + + +" +`; + +exports[`overlay should not show an error when "client.overlay" is "false": page html 1`] = ` +" + + +" +`; + +exports[`overlay should not show an error when "client.overlay.errors" is "false": page html 1`] = ` +" + + +" +`; + exports[`overlay should not show initially, then show on an error and allow to close: overlay html 1`] = ` "
Error:

- ./foo.js 1:1 Module parse failed: Unterminated template (1:1) You may - need an appropriate loader to handle this file type, currently no - loaders are configured to process this file. See + Module parse failed: Unterminated template (1:1) You may need an + appropriate loader to handle this file type, currently no loaders are + configured to process this file. See https://webpack.js.org/concepts#loaders > \`;


@@ -119,9 +147,9 @@ exports[`overlay should not show initially, then show on an error, then hide on
Error:

- ./foo.js 1:1 Module parse failed: Unterminated template (1:1) You may - need an appropriate loader to handle this file type, currently no - loaders are configured to process this file. See + Module parse failed: Unterminated template (1:1) You may need an + appropriate loader to handle this file type, currently no loaders are + configured to process this file. See https://webpack.js.org/concepts#loaders > \`;


@@ -201,9 +229,9 @@ exports[`overlay should not show initially, then show on an error, then show oth
Error:

- ./foo.js 1:1 Module parse failed: Unterminated template (1:1) You may - need an appropriate loader to handle this file type, currently no - loaders are configured to process this file. See + Module parse failed: Unterminated template (1:1) You may need an + appropriate loader to handle this file type, currently no loaders are + configured to process this file. See https://webpack.js.org/concepts#loaders > \`;


@@ -250,9 +278,9 @@ exports[`overlay should not show initially, then show on an error, then show oth
Error:

- ./foo.js 1:1 Module parse failed: Unterminated template (1:1) You may - need an appropriate loader to handle this file type, currently no - loaders are configured to process this file. See + Module parse failed: Unterminated template (1:1) You may need an + appropriate loader to handle this file type, currently no loaders are + configured to process this file. See https://webpack.js.org/concepts#loaders > \`;a


@@ -314,35 +342,7 @@ exports[`overlay should not show initially, then show on an error, then show oth " `; -exports[`overlay should not show on a warning when "client.overlay" is "false": page html 1`] = ` -" - - -" -`; - -exports[`overlay should not show on a warning when "client.overlay.warnings" is "false": page html 1`] = ` -" - - -" -`; - -exports[`overlay should not show on an error when "client.overlay" is "false": page html 1`] = ` -" - - -" -`; - -exports[`overlay should not show on an error when "client.overlay.errors" is "false": page html 1`] = ` -" - - -" -`; - -exports[`overlay should show on a warning and error for initial compilation and protects against xss: overlay html 1`] = ` +exports[`overlay should show a warning and error for initial compilation and protects against xss: overlay html 1`] = ` "
+ +" +`; + +exports[`overlay should show a warning and hide them after closing connection: page html 2`] = ` +" + + +" +`; + +exports[`overlay should show a warning for initial compilation: overlay html 1`] = ` "
+ +" +`; + +exports[`overlay should show a warning and hide them after closing connection: page html 2`] = ` +" + + +" +`; + +exports[`overlay should show a warning for initial compilation: overlay html 1`] = ` "