File tree Expand file tree Collapse file tree 4 files changed +61
-2
lines changed Expand file tree Collapse file tree 4 files changed +61
-2
lines changed Original file line number Diff line number Diff line change
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports [` misc parses Fragments 1` ] = ` "Hello"` ;
4
+
5
+ exports [` misc parses nested Fragments 1` ] = ` "Baz"` ;
Original file line number Diff line number Diff line change
1
+ import React , { Fragment } from 'react' ;
2
+ import ReactDOM from 'react-dom' ;
3
+ import Helmet from '../src' ;
4
+ import Provider from '../src/Provider' ;
5
+
6
+ Helmet . defaultProps . defer = false ;
7
+
8
+ const mount = document . getElementById ( 'mount' ) ;
9
+
10
+ const render = node => {
11
+ ReactDOM . render ( < Provider > { node } </ Provider > , mount ) ;
12
+ } ;
13
+
14
+ describe ( 'fragments' , ( ) => {
15
+ it ( 'parses Fragments' , ( ) => {
16
+ render (
17
+ < Helmet >
18
+ < Fragment >
19
+ < title > Hello</ title >
20
+ </ Fragment >
21
+ </ Helmet >
22
+ ) ;
23
+
24
+ expect ( document . title ) . toMatchSnapshot ( ) ;
25
+ } ) ;
26
+
27
+ it ( 'parses nested Fragments' , ( ) => {
28
+ render (
29
+ < Helmet >
30
+ < Fragment >
31
+ < title > Foo</ title >
32
+ < Fragment >
33
+ < title > Bar</ title >
34
+ < Fragment >
35
+ < title > Baz</ title >
36
+ </ Fragment >
37
+ </ Fragment >
38
+ </ Fragment >
39
+ </ Helmet >
40
+ ) ;
41
+
42
+ expect ( document . title ) . toMatchSnapshot ( ) ;
43
+ } ) ;
44
+ } ) ;
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ export const TAG_NAMES = {
28
28
SCRIPT : 'script' ,
29
29
STYLE : 'style' ,
30
30
TITLE : 'title' ,
31
+ FRAGMENT : 'Symbol(react.fragment)' ,
31
32
} ;
32
33
33
34
export const VALID_TAG_NAMES = Object . keys ( TAG_NAMES ) . map ( name => TAG_NAMES [ name ] ) ;
Original file line number Diff line number Diff line change @@ -179,9 +179,18 @@ export default class Helmet extends Component {
179
179
return obj ;
180
180
} , { } ) ;
181
181
182
- this . warnOnInvalidChildren ( child , nestedChildren ) ;
182
+ let { type } = child ;
183
+ if ( typeof type === 'symbol' ) {
184
+ type = type . toString ( ) ;
185
+ } else {
186
+ this . warnOnInvalidChildren ( child , nestedChildren ) ;
187
+ }
188
+
189
+ switch ( type ) {
190
+ case TAG_NAMES . FRAGMENT :
191
+ newProps = this . mapChildrenToProps ( nestedChildren , newProps ) ;
192
+ break ;
183
193
184
- switch ( child . type ) {
185
194
case TAG_NAMES . LINK :
186
195
case TAG_NAMES . META :
187
196
case TAG_NAMES . NOSCRIPT :
You can’t perform that action at this time.
0 commit comments