@@ -7,9 +7,22 @@ declare const __HMR_CONFIG_NAME__: string
7
7
const hmrConfigName = __HMR_CONFIG_NAME__
8
8
const base = __BASE__ || '/'
9
9
10
+ // Create an element with provided attributes and optional children
11
+ function h (
12
+ e : string ,
13
+ attrs : Record < string , string > = { } ,
14
+ ...children : ( string | Node ) [ ]
15
+ ) {
16
+ const elem = document . createElement ( e )
17
+ for ( const [ k , v ] of Object . entries ( attrs ) ) {
18
+ elem . setAttribute ( k , v )
19
+ }
20
+ elem . append ( ...children )
21
+ return elem
22
+ }
23
+
10
24
// set :host styles to make playwright detect the element as visible
11
- const template = /*html*/ `
12
- <style>
25
+ const templateStyle = /*css*/ `
13
26
:host {
14
27
position: fixed;
15
28
top: 0;
@@ -149,22 +162,43 @@ kbd {
149
162
border-color: rgb(54, 57, 64);
150
163
border-image: initial;
151
164
}
152
- </style>
153
- <div class="backdrop" part="backdrop">
154
- <div class="window" part="window">
155
- <pre class="message" part="message"><span class="plugin" part="plugin"></span><span class="message-body" part="message-body"></span></pre>
156
- <pre class="file" part="file"></pre>
157
- <pre class="frame" part="frame"></pre>
158
- <pre class="stack" part="stack"></pre>
159
- <div class="tip" part="tip">
160
- Click outside, press <kbd>Esc</kbd> key, or fix the code to dismiss.<br>
161
- You can also disable this overlay by setting
162
- <code part="config-option-name">server.hmr.overlay</code> to <code part="config-option-value">false</code> in <code part="config-file-name">${ hmrConfigName } .</code>
163
- </div>
164
- </div>
165
- </div>
166
165
`
167
166
167
+ // Error Template
168
+ const template = h (
169
+ 'div' ,
170
+ { class : 'backdrop' , part : 'backdrop' } ,
171
+ h (
172
+ 'div' ,
173
+ { class : 'window' , part : 'window' } ,
174
+ h (
175
+ 'pre' ,
176
+ { class : 'message' , part : 'message' } ,
177
+ h ( 'span' , { class : 'plugin' , part : 'plugin' } ) ,
178
+ h ( 'span' , { class : 'message-body' , part : 'message-body' } ) ,
179
+ ) ,
180
+ h ( 'pre' , { class : 'file' , part : 'file' } ) ,
181
+ h ( 'pre' , { class : 'frame' , part : 'frame' } ) ,
182
+ h ( 'pre' , { class : 'stack' , part : 'stack' } ) ,
183
+ h (
184
+ 'div' ,
185
+ { class : 'tip' , part : 'tip' } ,
186
+ 'Click outside, press ' ,
187
+ h ( 'kbd' , { } , 'Esc' ) ,
188
+ ' key, or fix the code to dismiss.' ,
189
+ h ( 'br' ) ,
190
+ 'You can also disable this overlay by setting ' ,
191
+ h ( 'code' , { part : 'config-option-name' } , 'server.hmr.overlay' ) ,
192
+ ' to ' ,
193
+ h ( 'code' , { part : 'config-option-value' } , 'false' ) ,
194
+ ' in ' ,
195
+ h ( 'code' , { part : 'config-file-name' } , hmrConfigName ) ,
196
+ '.' ,
197
+ ) ,
198
+ ) ,
199
+ h ( 'style' , { } , templateStyle ) ,
200
+ )
201
+
168
202
const fileRE = / (?: [ a - z A - Z ] : \\ | \/ ) .* ?: \d + : \d + / g
169
203
const codeframeRE = / ^ (?: > ? \s * \d + \s + \| .* | \s + \| \s * \^ .* ) \r ? \n / gm
170
204
@@ -178,7 +212,8 @@ export class ErrorOverlay extends HTMLElement {
178
212
constructor ( err : ErrorPayload [ 'err' ] , links = true ) {
179
213
super ( )
180
214
this . root = this . attachShadow ( { mode : 'open' } )
181
- this . root . innerHTML = template
215
+
216
+ this . root . appendChild ( template )
182
217
183
218
codeframeRE . lastIndex = 0
184
219
const hasFrame = err . frame && codeframeRE . test ( err . frame )
0 commit comments