preact-render-to-string 5.2.3 → 5.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.js CHANGED
@@ -1,366 +1,396 @@
1
- import {
2
- encodeEntities,
3
- styleObjToCss,
4
- getContext,
5
- createComponent,
6
- UNSAFE_NAME,
7
- XLINK,
8
- VOID_ELEMENTS
9
- } from './util';
10
- import { options, Fragment } from 'preact';
11
- import { _renderToStringPretty } from './pretty';
12
- import {
13
- COMMIT,
14
- COMPONENT,
15
- DIFF,
16
- DIFFED,
17
- DIRTY,
18
- NEXT_STATE,
19
- RENDER,
20
- SKIP_EFFECTS,
21
- VNODE
22
- } from './constants';
23
-
24
- /** @typedef {import('preact').VNode} VNode */
25
-
26
- const SHALLOW = { shallow: true };
27
-
28
- /** Render Preact JSX + Components to an HTML string.
29
- * @name render
30
- * @function
31
- * @param {VNode} vnode JSX VNode to render.
32
- * @param {Object} [context={}] Optionally pass an initial context object through the render path.
33
- * @param {Object} [options={}] Rendering options
34
- * @param {Boolean} [options.shallow=false] If `true`, renders nested Components as HTML elements (`<Foo a="b" />`).
35
- * @param {Boolean} [options.xml=false] If `true`, uses self-closing tags for elements without children.
36
- * @param {Boolean} [options.pretty=false] If `true`, adds whitespace for readability
37
- * @param {RegExp|undefined} [options.voidElements] RegeEx that matches elements that are considered void (self-closing)
38
- */
39
- renderToString.render = renderToString;
40
-
41
- /** Only render elements, leaving Components inline as `<ComponentName ... />`.
42
- * This method is just a convenience alias for `render(vnode, context, { shallow:true })`
43
- * @name shallow
44
- * @function
45
- * @param {VNode} vnode JSX VNode to render.
46
- * @param {Object} [context={}] Optionally pass an initial context object through the render path.
47
- */
48
- let shallowRender = (vnode, context) => renderToString(vnode, context, SHALLOW);
49
-
50
- const EMPTY_ARR = [];
51
- function renderToString(vnode, context, opts) {
52
- context = context || {};
53
-
54
- // Performance optimization: `renderToString` is synchronous and we
55
- // therefore don't execute any effects. To do that we pass an empty
56
- // array to `options._commit` (`__c`). But we can go one step further
57
- // and avoid a lot of dirty checks and allocations by setting
58
- // `options._skipEffects` (`__s`) too.
59
- const previousSkipEffects = options[SKIP_EFFECTS];
60
- options[SKIP_EFFECTS] = true;
61
-
62
- let res;
63
- if (
64
- opts &&
65
- (opts.pretty ||
66
- opts.voidElements ||
67
- opts.sortAttributes ||
68
- opts.shallow ||
69
- opts.allAttributes ||
70
- opts.xml ||
71
- opts.attributeHook)
72
- ) {
73
- res = _renderToStringPretty(vnode, context, opts);
74
- } else {
75
- res = _renderToString(vnode, context, false, undefined);
76
- }
77
-
78
- // options._commit, we don't schedule any effects in this library right now,
79
- // so we can pass an empty queue to this hook.
80
- if (options[COMMIT]) options[COMMIT](vnode, EMPTY_ARR);
81
- options[SKIP_EFFECTS] = previousSkipEffects;
82
- EMPTY_ARR.length = 0;
83
- return res;
84
- }
85
-
86
- function renderFunctionComponent(vnode, context) {
87
- let rendered,
88
- c = createComponent(vnode, context),
89
- cctx = getContext(vnode.type, context);
90
-
91
- vnode[COMPONENT] = c;
92
-
93
- // If a hook invokes setState() to invalidate the component during rendering,
94
- // re-render it up to 25 times to allow "settling" of memoized states.
95
- // Note:
96
- // This will need to be updated for Preact 11 to use internal.flags rather than component._dirty:
97
- // https://github.com/preactjs/preact/blob/d4ca6fdb19bc715e49fd144e69f7296b2f4daa40/src/diff/component.js#L35-L44
98
- let renderHook = options[RENDER];
99
- let count = 0;
100
- while (c[DIRTY] && count++ < 25) {
101
- c[DIRTY] = false;
102
-
103
- if (renderHook) renderHook(vnode);
104
-
105
- // stateless functional components
106
- rendered = vnode.type.call(c, vnode.props, cctx);
107
- }
108
-
109
- return rendered;
110
- }
111
-
112
- function renderClassComponent(vnode, context) {
113
- let nodeName = vnode.type,
114
- cctx = getContext(nodeName, context);
115
-
116
- // c = new nodeName(props, context);
117
- let c = new nodeName(vnode.props, cctx);
118
- vnode[COMPONENT] = c;
119
- c[VNODE] = vnode;
120
- // turn off stateful re-rendering:
121
- c[DIRTY] = true;
122
- c.props = vnode.props;
123
- if (c.state == null) c.state = {};
124
-
125
- if (c[NEXT_STATE] == null) {
126
- c[NEXT_STATE] = c.state;
127
- }
128
-
129
- c.context = cctx;
130
- if (nodeName.getDerivedStateFromProps) {
131
- c.state = assign(
132
- {},
133
- c.state,
134
- nodeName.getDerivedStateFromProps(c.props, c.state)
135
- );
136
- } else if (c.componentWillMount) {
137
- c.componentWillMount();
138
-
139
- // If the user called setState in cWM we need to flush pending,
140
- // state updates. This is the same behaviour in React.
141
- c.state = c[NEXT_STATE] !== c.state ? c[NEXT_STATE] : c.state;
142
- }
143
-
144
- let renderHook = options[RENDER];
145
- if (renderHook) renderHook(vnode);
146
-
147
- return c.render(c.props, c.state, c.context);
148
- }
149
-
150
- function normalizePropName(name, isSvgMode) {
151
- if (name === 'className') {
152
- return 'class';
153
- } else if (name === 'htmlFor') {
154
- return 'for';
155
- } else if (name === 'defaultValue') {
156
- return 'value';
157
- } else if (name === 'defaultChecked') {
158
- return 'checked';
159
- } else if (name === 'defaultSelected') {
160
- return 'selected';
161
- } else if (isSvgMode && XLINK.test(name)) {
162
- return name.toLowerCase().replace(/^xlink:?/, 'xlink:');
163
- }
164
-
165
- return name;
166
- }
167
-
168
- function normalizePropValue(name, v) {
169
- if (name === 'style' && v != null && typeof v === 'object') {
170
- return styleObjToCss(v);
171
- } else if (name[0] === 'a' && name[1] === 'r' && typeof v === 'boolean') {
172
- // always use string values instead of booleans for aria attributes
173
- // also see https://github.com/preactjs/preact/pull/2347/files
174
- return String(v);
175
- }
176
-
177
- return v;
178
- }
179
-
180
- const isArray = Array.isArray;
181
- const assign = Object.assign;
182
-
183
- /** The default export is an alias of `render()`. */
184
- function _renderToString(vnode, context, isSvgMode, selectValue) {
185
- // Ignore non-rendered VNodes/values
186
- if (vnode == null || vnode === true || vnode === false || vnode === '') {
187
- return '';
188
- }
189
-
190
- // Text VNodes: escape as HTML
191
- if (typeof vnode !== 'object') {
192
- return encodeEntities(vnode);
193
- }
194
-
195
- // Recurse into children / Arrays
196
- if (isArray(vnode)) {
197
- let rendered = '';
198
- for (let i = 0; i < vnode.length; i++) {
199
- rendered =
200
- rendered + _renderToString(vnode[i], context, isSvgMode, selectValue);
201
- }
202
- return rendered;
203
- }
204
-
205
- if (options[DIFF]) options[DIFF](vnode);
206
-
207
- let type = vnode.type,
208
- props = vnode.props;
209
-
210
- // Invoke rendering on Components
211
- const isComponent = typeof type === 'function';
212
- if (isComponent) {
213
- if (type === Fragment) {
214
- return _renderToString(
215
- vnode.props.children,
216
- context,
217
- isSvgMode,
218
- selectValue
219
- );
220
- }
221
-
222
- let rendered;
223
- if (type.prototype && typeof type.prototype.render === 'function') {
224
- rendered = renderClassComponent(vnode, context);
225
- } else {
226
- rendered = renderFunctionComponent(vnode, context);
227
- }
228
-
229
- let component = vnode[COMPONENT];
230
- if (component.getChildContext) {
231
- context = assign({}, context, component.getChildContext());
232
- }
233
-
234
- // Recurse into children before invoking the after-diff hook
235
- const str = _renderToString(rendered, context, isSvgMode, selectValue);
236
- if (options[DIFFED]) options[DIFFED](vnode);
237
- return str;
238
- }
239
-
240
- // Serialize Element VNodes to HTML
241
- let s = '<',
242
- children,
243
- html;
244
-
245
- s = s + type;
246
-
247
- if (props) {
248
- children = props.children;
249
- for (let name in props) {
250
- let v = props[name];
251
-
252
- if (
253
- name === 'key' ||
254
- name === 'ref' ||
255
- name === '__self' ||
256
- name === '__source' ||
257
- name === 'children' ||
258
- (name === 'className' && 'class' in props) ||
259
- (name === 'htmlFor' && 'for' in props)
260
- ) {
261
- continue;
262
- }
263
-
264
- if (UNSAFE_NAME.test(name)) continue;
265
-
266
- name = normalizePropName(name, isSvgMode);
267
- v = normalizePropValue(name, v);
268
-
269
- if (name === 'dangerouslySetInnerHTML') {
270
- html = v && v.__html;
271
- } else if (type === 'textarea' && name === 'value') {
272
- // <textarea value="a&b"> --> <textarea>a&amp;b</textarea>
273
- children = v;
274
- } else if ((v || v === 0 || v === '') && typeof v !== 'function') {
275
- if (v === true || v === '') {
276
- v = name;
277
- s = s + ' ' + name;
278
- continue;
279
- }
280
-
281
- if (name === 'value') {
282
- if (type === 'select') {
283
- selectValue = v;
284
- continue;
285
- } else if (
286
- // If we're looking at an <option> and it's the currently selected one
287
- type === 'option' &&
288
- selectValue == v &&
289
- // and the <option> doesn't already have a selected attribute on it
290
- !('selected' in props)
291
- ) {
292
- s = s + ' selected';
293
- }
294
- }
295
- s = s + ' ' + name + '="' + encodeEntities(v) + '"';
296
- }
297
- }
298
- }
299
-
300
- let startElement = s;
301
- s = s + '>';
302
-
303
- if (UNSAFE_NAME.test(type)) {
304
- throw new Error(`${type} is not a valid HTML tag name in ${s}`);
305
- }
306
-
307
- let pieces = '';
308
- let hasChildren = false;
309
-
310
- if (html) {
311
- pieces = pieces + html;
312
- hasChildren = true;
313
- } else if (typeof children === 'string') {
314
- pieces = pieces + encodeEntities(children);
315
- hasChildren = true;
316
- } else if (isArray(children)) {
317
- for (let i = 0; i < children.length; i++) {
318
- let child = children[i];
319
-
320
- if (child != null && child !== false) {
321
- let childSvgMode =
322
- type === 'svg' || (type !== 'foreignObject' && isSvgMode);
323
- let ret = _renderToString(child, context, childSvgMode, selectValue);
324
-
325
- // Skip if we received an empty string
326
- if (ret) {
327
- pieces = pieces + ret;
328
- hasChildren = true;
329
- }
330
- }
331
- }
332
- } else if (children != null && children !== false && children !== true) {
333
- let childSvgMode =
334
- type === 'svg' || (type !== 'foreignObject' && isSvgMode);
335
- let ret = _renderToString(children, context, childSvgMode, selectValue);
336
-
337
- // Skip if we received an empty string
338
- if (ret) {
339
- pieces = pieces + ret;
340
- hasChildren = true;
341
- }
342
- }
343
-
344
- if (options[DIFFED]) options[DIFFED](vnode);
345
-
346
- if (hasChildren) {
347
- s = s + pieces;
348
- } else if (VOID_ELEMENTS.test(type)) {
349
- return startElement + ' />';
350
- }
351
-
352
- return s + '</' + type + '>';
353
- }
354
-
355
- /** The default export is an alias of `render()`. */
356
-
357
- renderToString.shallowRender = shallowRender;
358
-
359
- export default renderToString;
360
-
361
- export {
362
- renderToString as render,
363
- renderToString as renderToStaticMarkup,
364
- renderToString,
365
- shallowRender
366
- };
1
+ import {
2
+ encodeEntities,
3
+ styleObjToCss,
4
+ getContext,
5
+ createComponent,
6
+ UNSAFE_NAME,
7
+ XLINK,
8
+ VOID_ELEMENTS
9
+ } from './util';
10
+ import { options, h, Fragment } from 'preact';
11
+ import { _renderToStringPretty } from './pretty';
12
+ import {
13
+ COMMIT,
14
+ COMPONENT,
15
+ DIFF,
16
+ DIFFED,
17
+ DIRTY,
18
+ NEXT_STATE,
19
+ PARENT,
20
+ RENDER,
21
+ SKIP_EFFECTS,
22
+ VNODE,
23
+ CHILDREN
24
+ } from './constants';
25
+
26
+ /** @typedef {import('preact').VNode} VNode */
27
+
28
+ const SHALLOW = { shallow: true };
29
+
30
+ /** Render Preact JSX + Components to an HTML string.
31
+ * @name render
32
+ * @function
33
+ * @param {VNode} vnode JSX VNode to render.
34
+ * @param {Object} [context={}] Optionally pass an initial context object through the render path.
35
+ * @param {Object} [options={}] Rendering options
36
+ * @param {Boolean} [options.shallow=false] If `true`, renders nested Components as HTML elements (`<Foo a="b" />`).
37
+ * @param {Boolean} [options.xml=false] If `true`, uses self-closing tags for elements without children.
38
+ * @param {Boolean} [options.pretty=false] If `true`, adds whitespace for readability
39
+ * @param {RegExp|undefined} [options.voidElements] RegeEx that matches elements that are considered void (self-closing)
40
+ */
41
+ renderToString.render = renderToString;
42
+
43
+ /** Only render elements, leaving Components inline as `<ComponentName ... />`.
44
+ * This method is just a convenience alias for `render(vnode, context, { shallow:true })`
45
+ * @name shallow
46
+ * @function
47
+ * @param {VNode} vnode JSX VNode to render.
48
+ * @param {Object} [context={}] Optionally pass an initial context object through the render path.
49
+ */
50
+ let shallowRender = (vnode, context) => renderToString(vnode, context, SHALLOW);
51
+
52
+ const EMPTY_ARR = [];
53
+ function renderToString(vnode, context, opts) {
54
+ context = context || {};
55
+
56
+ // Performance optimization: `renderToString` is synchronous and we
57
+ // therefore don't execute any effects. To do that we pass an empty
58
+ // array to `options._commit` (`__c`). But we can go one step further
59
+ // and avoid a lot of dirty checks and allocations by setting
60
+ // `options._skipEffects` (`__s`) too.
61
+ const previousSkipEffects = options[SKIP_EFFECTS];
62
+ options[SKIP_EFFECTS] = true;
63
+
64
+ const parent = h(Fragment, null);
65
+ parent[CHILDREN] = [vnode];
66
+
67
+ let res;
68
+ if (
69
+ opts &&
70
+ (opts.pretty ||
71
+ opts.voidElements ||
72
+ opts.sortAttributes ||
73
+ opts.shallow ||
74
+ opts.allAttributes ||
75
+ opts.xml ||
76
+ opts.attributeHook)
77
+ ) {
78
+ res = _renderToStringPretty(vnode, context, opts);
79
+ } else {
80
+ res = _renderToString(vnode, context, false, undefined, parent);
81
+ }
82
+
83
+ // options._commit, we don't schedule any effects in this library right now,
84
+ // so we can pass an empty queue to this hook.
85
+ if (options[COMMIT]) options[COMMIT](vnode, EMPTY_ARR);
86
+ options[SKIP_EFFECTS] = previousSkipEffects;
87
+ EMPTY_ARR.length = 0;
88
+
89
+ return res;
90
+ }
91
+
92
+ function renderFunctionComponent(vnode, context) {
93
+ let rendered,
94
+ c = createComponent(vnode, context),
95
+ cctx = getContext(vnode.type, context);
96
+
97
+ vnode[COMPONENT] = c;
98
+
99
+ // If a hook invokes setState() to invalidate the component during rendering,
100
+ // re-render it up to 25 times to allow "settling" of memoized states.
101
+ // Note:
102
+ // This will need to be updated for Preact 11 to use internal.flags rather than component._dirty:
103
+ // https://github.com/preactjs/preact/blob/d4ca6fdb19bc715e49fd144e69f7296b2f4daa40/src/diff/component.js#L35-L44
104
+ let renderHook = options[RENDER];
105
+ let count = 0;
106
+ while (c[DIRTY] && count++ < 25) {
107
+ c[DIRTY] = false;
108
+
109
+ if (renderHook) renderHook(vnode);
110
+
111
+ // stateless functional components
112
+ rendered = vnode.type.call(c, vnode.props, cctx);
113
+ }
114
+
115
+ return rendered;
116
+ }
117
+
118
+ function renderClassComponent(vnode, context) {
119
+ let nodeName = vnode.type,
120
+ cctx = getContext(nodeName, context);
121
+
122
+ // c = new nodeName(props, context);
123
+ let c = new nodeName(vnode.props, cctx);
124
+ vnode[COMPONENT] = c;
125
+ c[VNODE] = vnode;
126
+ // turn off stateful re-rendering:
127
+ c[DIRTY] = true;
128
+ c.props = vnode.props;
129
+ if (c.state == null) c.state = {};
130
+
131
+ if (c[NEXT_STATE] == null) {
132
+ c[NEXT_STATE] = c.state;
133
+ }
134
+
135
+ c.context = cctx;
136
+ if (nodeName.getDerivedStateFromProps) {
137
+ c.state = assign(
138
+ {},
139
+ c.state,
140
+ nodeName.getDerivedStateFromProps(c.props, c.state)
141
+ );
142
+ } else if (c.componentWillMount) {
143
+ c.componentWillMount();
144
+
145
+ // If the user called setState in cWM we need to flush pending,
146
+ // state updates. This is the same behaviour in React.
147
+ c.state = c[NEXT_STATE] !== c.state ? c[NEXT_STATE] : c.state;
148
+ }
149
+
150
+ let renderHook = options[RENDER];
151
+ if (renderHook) renderHook(vnode);
152
+
153
+ return c.render(c.props, c.state, c.context);
154
+ }
155
+
156
+ function normalizePropName(name, isSvgMode) {
157
+ if (name === 'className') {
158
+ return 'class';
159
+ } else if (name === 'htmlFor') {
160
+ return 'for';
161
+ } else if (name === 'defaultValue') {
162
+ return 'value';
163
+ } else if (name === 'defaultChecked') {
164
+ return 'checked';
165
+ } else if (name === 'defaultSelected') {
166
+ return 'selected';
167
+ } else if (isSvgMode && XLINK.test(name)) {
168
+ return name.toLowerCase().replace(/^xlink:?/, 'xlink:');
169
+ }
170
+
171
+ return name;
172
+ }
173
+
174
+ function normalizePropValue(name, v) {
175
+ if (name === 'style' && v != null && typeof v === 'object') {
176
+ return styleObjToCss(v);
177
+ } else if (name[0] === 'a' && name[1] === 'r' && typeof v === 'boolean') {
178
+ // always use string values instead of booleans for aria attributes
179
+ // also see https://github.com/preactjs/preact/pull/2347/files
180
+ return String(v);
181
+ }
182
+
183
+ return v;
184
+ }
185
+
186
+ const isArray = Array.isArray;
187
+ const assign = Object.assign;
188
+
189
+ /** The default export is an alias of `render()`. */
190
+ function _renderToString(vnode, context, isSvgMode, selectValue, parent) {
191
+ // Ignore non-rendered VNodes/values
192
+ if (vnode == null || vnode === true || vnode === false || vnode === '') {
193
+ return '';
194
+ }
195
+
196
+ // Text VNodes: escape as HTML
197
+ if (typeof vnode !== 'object') {
198
+ return encodeEntities(vnode);
199
+ }
200
+
201
+ // Recurse into children / Arrays
202
+ if (isArray(vnode)) {
203
+ let rendered = '';
204
+ parent[CHILDREN] = vnode;
205
+ for (let i = 0; i < vnode.length; i++) {
206
+ rendered =
207
+ rendered +
208
+ _renderToString(vnode[i], context, isSvgMode, selectValue, parent);
209
+ }
210
+ return rendered;
211
+ }
212
+
213
+ vnode[PARENT] = parent;
214
+ if (options[DIFF]) options[DIFF](vnode);
215
+
216
+ let type = vnode.type,
217
+ props = vnode.props;
218
+
219
+ // Invoke rendering on Components
220
+ const isComponent = typeof type === 'function';
221
+ if (isComponent) {
222
+ let rendered;
223
+ if (type === Fragment) {
224
+ rendered = props.children;
225
+ } else {
226
+ if (type.prototype && typeof type.prototype.render === 'function') {
227
+ rendered = renderClassComponent(vnode, context);
228
+ } else {
229
+ rendered = renderFunctionComponent(vnode, context);
230
+ }
231
+
232
+ let component = vnode[COMPONENT];
233
+ if (component.getChildContext) {
234
+ context = assign({}, context, component.getChildContext());
235
+ }
236
+ }
237
+
238
+ // Recurse into children before invoking the after-diff hook
239
+ const str = _renderToString(
240
+ rendered,
241
+ context,
242
+ isSvgMode,
243
+ selectValue,
244
+ vnode
245
+ );
246
+
247
+ if (options[DIFFED]) options[DIFFED](vnode);
248
+ vnode[PARENT] = undefined;
249
+
250
+ if (options.unmount) options.unmount(vnode);
251
+
252
+ return str;
253
+ }
254
+
255
+ // Serialize Element VNodes to HTML
256
+ let s = '<',
257
+ children,
258
+ html;
259
+
260
+ s = s + type;
261
+
262
+ if (props) {
263
+ children = props.children;
264
+ for (let name in props) {
265
+ let v = props[name];
266
+
267
+ if (
268
+ name === 'key' ||
269
+ name === 'ref' ||
270
+ name === '__self' ||
271
+ name === '__source' ||
272
+ name === 'children' ||
273
+ (name === 'className' && 'class' in props) ||
274
+ (name === 'htmlFor' && 'for' in props)
275
+ ) {
276
+ continue;
277
+ }
278
+
279
+ if (UNSAFE_NAME.test(name)) continue;
280
+
281
+ name = normalizePropName(name, isSvgMode);
282
+ v = normalizePropValue(name, v);
283
+
284
+ if (name === 'dangerouslySetInnerHTML') {
285
+ html = v && v.__html;
286
+ } else if (type === 'textarea' && name === 'value') {
287
+ // <textarea value="a&b"> --> <textarea>a&amp;b</textarea>
288
+ children = v;
289
+ } else if ((v || v === 0 || v === '') && typeof v !== 'function') {
290
+ if (v === true || v === '') {
291
+ v = name;
292
+ s = s + ' ' + name;
293
+ continue;
294
+ }
295
+
296
+ if (name === 'value') {
297
+ if (type === 'select') {
298
+ selectValue = v;
299
+ continue;
300
+ } else if (
301
+ // If we're looking at an <option> and it's the currently selected one
302
+ type === 'option' &&
303
+ selectValue == v &&
304
+ // and the <option> doesn't already have a selected attribute on it
305
+ !('selected' in props)
306
+ ) {
307
+ s = s + ' selected';
308
+ }
309
+ }
310
+ s = s + ' ' + name + '="' + encodeEntities(v) + '"';
311
+ }
312
+ }
313
+ }
314
+
315
+ let startElement = s;
316
+ s = s + '>';
317
+
318
+ if (UNSAFE_NAME.test(type)) {
319
+ throw new Error(`${type} is not a valid HTML tag name in ${s}`);
320
+ }
321
+
322
+ let pieces = '';
323
+ let hasChildren = false;
324
+
325
+ if (html) {
326
+ pieces = pieces + html;
327
+ hasChildren = true;
328
+ } else if (typeof children === 'string') {
329
+ pieces = pieces + encodeEntities(children);
330
+ hasChildren = true;
331
+ } else if (isArray(children)) {
332
+ vnode[CHILDREN] = children;
333
+ for (let i = 0; i < children.length; i++) {
334
+ let child = children[i];
335
+ if (child != null && child !== false) {
336
+ let childSvgMode =
337
+ type === 'svg' || (type !== 'foreignObject' && isSvgMode);
338
+ let ret = _renderToString(
339
+ child,
340
+ context,
341
+ childSvgMode,
342
+ selectValue,
343
+ vnode
344
+ );
345
+
346
+ // Skip if we received an empty string
347
+ if (ret) {
348
+ pieces = pieces + ret;
349
+ hasChildren = true;
350
+ }
351
+ }
352
+ }
353
+ } else if (children != null && children !== false && children !== true) {
354
+ vnode[CHILDREN] = [children];
355
+ let childSvgMode =
356
+ type === 'svg' || (type !== 'foreignObject' && isSvgMode);
357
+ let ret = _renderToString(
358
+ children,
359
+ context,
360
+ childSvgMode,
361
+ selectValue,
362
+ vnode
363
+ );
364
+
365
+ // Skip if we received an empty string
366
+ if (ret) {
367
+ pieces = pieces + ret;
368
+ hasChildren = true;
369
+ }
370
+ }
371
+
372
+ if (options[DIFFED]) options[DIFFED](vnode);
373
+ vnode[PARENT] = undefined;
374
+ if (options.unmount) options.unmount(vnode);
375
+
376
+ if (hasChildren) {
377
+ s = s + pieces;
378
+ } else if (VOID_ELEMENTS.test(type)) {
379
+ return startElement + ' />';
380
+ }
381
+
382
+ return s + '</' + type + '>';
383
+ }
384
+
385
+ /** The default export is an alias of `render()`. */
386
+
387
+ renderToString.shallowRender = shallowRender;
388
+
389
+ export default renderToString;
390
+
391
+ export {
392
+ renderToString as render,
393
+ renderToString as renderToStaticMarkup,
394
+ renderToString,
395
+ shallowRender
396
+ };