@@ -22,143 +22,10 @@ var SockJS = require('sockjs-client');
2222var stripAnsi = require ( 'strip-ansi' ) ;
2323var url = require ( 'url' ) ;
2424var formatWebpackMessages = require ( './formatWebpackMessages' ) ;
25- var Entities = require ( 'html-entities' ) . AllHtmlEntities ;
26- var ansiHTML = require ( './ansiHTML' ) ;
27- var entities = new Entities ( ) ;
28-
29- function createOverlayIframe ( onIframeLoad ) {
30- var iframe = document . createElement ( 'iframe' ) ;
31- iframe . id = 'react-dev-utils-webpack-hot-dev-client-overlay' ;
32- iframe . src = 'about:blank' ;
33- iframe . style . position = 'fixed' ;
34- iframe . style . left = 0 ;
35- iframe . style . top = 0 ;
36- iframe . style . right = 0 ;
37- iframe . style . bottom = 0 ;
38- iframe . style . width = '100vw' ;
39- iframe . style . height = '100vh' ;
40- iframe . style . border = 'none' ;
41- iframe . style . zIndex = 2147483647 ;
42- iframe . onload = onIframeLoad ;
43- return iframe ;
44- }
45-
46- function addOverlayDivTo ( iframe ) {
47- // TODO: unify these styles with react-error-overlay
48- iframe . contentDocument . body . style . margin = 0 ;
49- iframe . contentDocument . body . style . maxWidth = '100vw' ;
50-
51- var outerDiv = iframe . contentDocument . createElement ( 'div' ) ;
52- outerDiv . id = 'react-dev-utils-webpack-hot-dev-client-overlay-div' ;
53- outerDiv . style . width = '100%' ;
54- outerDiv . style . height = '100%' ;
55- outerDiv . style . boxSizing = 'border-box' ;
56- outerDiv . style . textAlign = 'center' ;
57- outerDiv . style . backgroundColor = 'rgb(255, 255, 255)' ;
58-
59- var div = iframe . contentDocument . createElement ( 'div' ) ;
60- div . style . position = 'relative' ;
61- div . style . display = 'inline-flex' ;
62- div . style . flexDirection = 'column' ;
63- div . style . height = '100%' ;
64- div . style . width = '1024px' ;
65- div . style . maxWidth = '100%' ;
66- div . style . overflowX = 'hidden' ;
67- div . style . overflowY = 'auto' ;
68- div . style . padding = '0.5rem' ;
69- div . style . boxSizing = 'border-box' ;
70- div . style . textAlign = 'left' ;
71- div . style . fontFamily = 'Consolas, Menlo, monospace' ;
72- div . style . fontSize = '11px' ;
73- div . style . whiteSpace = 'pre-wrap' ;
74- div . style . wordBreak = 'break-word' ;
75- div . style . lineHeight = '1.5' ;
76- div . style . color = 'rgb(41, 50, 56)' ;
77-
78- outerDiv . appendChild ( div ) ;
79- iframe . contentDocument . body . appendChild ( outerDiv ) ;
80- return div ;
81- }
82-
83- function overlayHeaderStyle ( ) {
84- return (
85- 'font-size: 2em;' +
86- 'font-family: sans-serif;' +
87- 'color: rgb(206, 17, 38);' +
88- 'white-space: pre-wrap;' +
89- 'margin: 0 2rem 0.75rem 0px;' +
90- 'flex: 0 0 auto;' +
91- 'max-height: 35%;' +
92- 'overflow: auto;'
93- ) ;
94- }
95-
96- var overlayIframe = null ;
97- var overlayDiv = null ;
98- var lastOnOverlayDivReady = null ;
99-
100- function ensureOverlayDivExists ( onOverlayDivReady ) {
101- if ( overlayDiv ) {
102- // Everything is ready, call the callback right away.
103- onOverlayDivReady ( overlayDiv ) ;
104- return ;
105- }
106-
107- // Creating an iframe may be asynchronous so we'll schedule the callback.
108- // In case of multiple calls, last callback wins.
109- lastOnOverlayDivReady = onOverlayDivReady ;
110-
111- if ( overlayIframe ) {
112- // We're already creating it.
113- return ;
114- }
25+ var showCompileErrorOverlay = require ( 'react-error-overlay' )
26+ . showCompileErrorOverlay ;
11527
116- // Create iframe and, when it is ready, a div inside it.
117- overlayIframe = createOverlayIframe ( function onIframeLoad ( ) {
118- overlayDiv = addOverlayDivTo ( overlayIframe ) ;
119- // Now we can talk!
120- lastOnOverlayDivReady ( overlayDiv ) ;
121- } ) ;
122-
123- // Zalgo alert: onIframeLoad() will be called either synchronously
124- // or asynchronously depending on the browser.
125- // We delay adding it so `overlayIframe` is set when `onIframeLoad` fires.
126- document . body . appendChild ( overlayIframe ) ;
127- }
128-
129- function showErrorOverlay ( message ) {
130- ensureOverlayDivExists ( function onOverlayDivReady ( overlayDiv ) {
131- // TODO: unify this with our runtime overlay
132- overlayDiv . innerHTML =
133- '<div style="' +
134- overlayHeaderStyle ( ) +
135- '">Failed to compile</div>' +
136- '<pre style="' +
137- 'display: block; padding: 0.5em; margin-top: 0; ' +
138- 'margin-bottom: 0.5em; overflow-x: auto; white-space: pre-wrap; ' +
139- 'border-radius: 0.25rem; background-color: rgba(206, 17, 38, 0.05)">' +
140- '<code style="font-family: Consolas, Menlo, monospace;">' +
141- ansiHTML ( entities . encode ( message ) ) +
142- '</code></pre>' +
143- '<div style="' +
144- 'font-family: sans-serif; color: rgb(135, 142, 145); margin-top: 0.5rem; ' +
145- 'flex: 0 0 auto">' +
146- 'This error occurred during the build time and cannot be dismissed.</div>' ;
147- } ) ;
148- }
149-
150- function destroyErrorOverlay ( ) {
151- if ( ! overlayDiv ) {
152- // It is not there in the first place.
153- return ;
154- }
155-
156- // Clean up and reset internal state.
157- document . body . removeChild ( overlayIframe ) ;
158- overlayDiv = null ;
159- overlayIframe = null ;
160- lastOnOverlayDivReady = null ;
161- }
28+ var destroyOverlay = null ;
16229
16330// Connect to WebpackDevServer via a socket.
16431var connection = new SockJS (
@@ -209,7 +76,9 @@ function handleSuccess() {
20976 tryApplyUpdates ( function onHotUpdateSuccess ( ) {
21077 // Only destroy it when we're sure it's a hot update.
21178 // Otherwise it would flicker right before the reload.
212- destroyErrorOverlay ( ) ;
79+ if ( destroyOverlay ) {
80+ destroyOverlay ( ) ;
81+ }
21382 } ) ;
21483 }
21584}
@@ -251,7 +120,9 @@ function handleWarnings(warnings) {
251120 printWarnings ( ) ;
252121 // Only destroy it when we're sure it's a hot update.
253122 // Otherwise it would flicker right before the reload.
254- destroyErrorOverlay ( ) ;
123+ if ( destroyOverlay ) {
124+ destroyOverlay ( ) ;
125+ }
255126 } ) ;
256127 } else {
257128 // Print initial warnings immediately.
@@ -273,7 +144,7 @@ function handleErrors(errors) {
273144 } ) ;
274145
275146 // Only show the first error.
276- showErrorOverlay ( formatted . errors [ 0 ] ) ;
147+ destroyOverlay = showCompileErrorOverlay ( formatted . errors [ 0 ] ) ;
277148
278149 // Also log them to the console.
279150 if ( typeof console !== 'undefined' && typeof console . error === 'function' ) {
0 commit comments