@@ -47,7 +47,13 @@ export default function renderToString(vnode, context) {
47
47
parent [ CHILDREN ] = [ vnode ] ;
48
48
49
49
try {
50
- return _renderToString ( vnode , context || { } , false , undefined , parent ) ;
50
+ return _renderToString (
51
+ vnode ,
52
+ context || EMPTY_OBJ ,
53
+ false ,
54
+ undefined ,
55
+ parent
56
+ ) ;
51
57
} finally {
52
58
// options._commit, we don't schedule any effects in this library right now,
53
59
// so we can pass an empty queue to this hook.
@@ -62,6 +68,8 @@ function markAsDirty() {
62
68
this . __d = true ;
63
69
}
64
70
71
+ const EMPTY_OBJ = { } ;
72
+
65
73
/**
66
74
* @param {VNode } vnode
67
75
* @param {Record<string, unknown> } context
@@ -79,7 +87,7 @@ function renderClassComponent(vnode, context) {
79
87
// turn off stateful re-rendering:
80
88
c [ DIRTY ] = true ;
81
89
82
- if ( c . state == null ) c . state = { } ;
90
+ if ( c . state == null ) c . state = EMPTY_OBJ ;
83
91
84
92
if ( c [ NEXT_STATE ] == null ) {
85
93
c [ NEXT_STATE ] = c . state ;
@@ -163,8 +171,7 @@ function _renderToString(vnode, context, isSvgMode, selectValue, parent) {
163
171
component ;
164
172
165
173
// Invoke rendering on Components
166
- let isComponent = typeof type === 'function' ;
167
- if ( isComponent ) {
174
+ if ( typeof type === 'function' ) {
168
175
if ( type === Fragment ) {
169
176
rendered = props . children ;
170
177
} else {
@@ -307,15 +314,16 @@ function _renderToString(vnode, context, isSvgMode, selectValue, parent) {
307
314
}
308
315
break ;
309
316
310
- default :
317
+ default : {
311
318
if ( isSvgMode && XLINK . test ( name ) ) {
312
- name = name . toLowerCase ( ) . replace ( / ^ x l i n k : ? / , 'xlink:' ) ;
319
+ name = name . toLowerCase ( ) . replace ( XLINK_REPLACE_REGEX , 'xlink:' ) ;
313
320
} else if ( UNSAFE_NAME . test ( name ) ) {
314
321
continue ;
315
322
} else if ( name [ 0 ] === 'a' && name [ 1 ] === 'r' && v != null ) {
316
323
// serialize boolean aria-xyz attribute values as strings
317
324
v += '' ;
318
325
}
326
+ }
319
327
}
320
328
321
329
// write this attribute to the buffer
@@ -349,25 +357,29 @@ function _renderToString(vnode, context, isSvgMode, selectValue, parent) {
349
357
if ( options . unmount ) options . unmount ( vnode ) ;
350
358
351
359
// Emit self-closing tag for empty void elements:
352
- if ( ! html ) {
353
- switch ( type ) {
354
- case 'area' :
355
- case 'base' :
356
- case 'br' :
357
- case 'col' :
358
- case 'embed' :
359
- case 'hr' :
360
- case 'img' :
361
- case 'input' :
362
- case 'link' :
363
- case 'meta' :
364
- case 'param' :
365
- case 'source' :
366
- case 'track' :
367
- case 'wbr' :
368
- return s + ' />' ;
369
- }
360
+ if ( ! html && SELF_CLOSING . has ( type ) ) {
361
+ return s + ' />' ;
370
362
}
371
363
372
364
return s + '>' + html + '</' + type + '>' ;
373
365
}
366
+
367
+ const XLINK_REPLACE_REGEX = / ^ x l i n k : ? / ;
368
+ const SELF_CLOSING = new Set ( [
369
+ 'area' ,
370
+ 'base' ,
371
+ 'br' ,
372
+ 'col' ,
373
+ 'command' ,
374
+ 'embed' ,
375
+ 'hr' ,
376
+ 'img' ,
377
+ 'input' ,
378
+ 'keygen' ,
379
+ 'link' ,
380
+ 'meta' ,
381
+ 'param' ,
382
+ 'source' ,
383
+ 'track' ,
384
+ 'wbr'
385
+ ] ) ;
0 commit comments