[v2] 2.0.0-17 SSR can contains conflicting keys
See original GitHub issueHi, I’m using styled-component with Next.js and found out the SSR in 2.0.0-17 can produce style elements with the same keys
.
const main = sheet.collectStyles(<Main />);
const styleTags = sheet.getStyleElement();
console.log(styleTags);
next_1 | [ { '$$typeof': Symbol(react.element),
next_1 | type: 'style',
next_1 | key: 'fNItctcyArQf',
next_1 | ref: null,
next_1 | props:
next_1 | { type: 'text/css',
next_1 | 'data-styled-components': 'fNItct cyArQf',
next_1 | 'data-styled-components-is-local': 'true',
next_1 | dangerouslySetInnerHTML: [Object] },
next_1 | _owner:
next_1 | ReactCompositeComponentWrapper {...},
next_1 | _store: {} },
next_1 | { '$$typeof': Symbol(react.element),
next_1 | type: 'style',
next_1 | key: '',
next_1 | ref: null,
next_1 | props:
next_1 | { type: 'text/css',
next_1 | 'data-styled-components': '',
next_1 | 'data-styled-components-is-local': 'false',
next_1 | dangerouslySetInnerHTML: [Object] },
next_1 | _owner:
next_1 | ReactCompositeComponentWrapper {...},
next_1 | _store: {} },
next_1 | { '$$typeof': Symbol(react.element),
next_1 | type: 'style',
next_1 | key: 'boZsUk',
next_1 | ref: null,
next_1 | props:
next_1 | { type: 'text/css',
next_1 | 'data-styled-components': 'boZsUk',
next_1 | 'data-styled-components-is-local': 'true',
next_1 | dangerouslySetInnerHTML: [Object] },
next_1 | _owner:
next_1 | ReactCompositeComponentWrapper {...},
next_1 | _store: {} },
next_1 | { '$$typeof': Symbol(react.element),
next_1 | type: 'style',
next_1 | key: '',
next_1 | ref: null,
next_1 | props:
next_1 | { type: 'text/css',
next_1 | 'data-styled-components': '',
next_1 | 'data-styled-components-is-local': 'false',
next_1 | dangerouslySetInnerHTML: [Object] },
next_1 | _owner:
next_1 | ReactCompositeComponentWrapper {...},
next_1 | _store: {} },
next_1 | { '$$typeof': Symbol(react.element),
next_1 | type: 'style',
next_1 | key: 'fbMseBbPlOHciZIztWijwppWcYHBKnVUVurkOMPXzexiBkeKdYRFdpNGlqiGXYPIfWzfGwdWMukr',
next_1 | ref: null,
next_1 | props:
next_1 | { type: 'text/css',
next_1 | 'data-styled-components': 'fbMseB bPlOHc iZIztW ijwppW cYHBKn VUVur kOMPXz exiBke KdYRF dpNGlq iGXYPI fWzfGw dWMukr',
next_1 | 'data-styled-components-is-local': 'true',
next_1 | dangerouslySetInnerHTML: [Object] },
next_1 | _owner:
next_1 | ReactCompositeComponentWrapper {...},
next_1 | _store: {} } ]
next_1 | Warning: flattenChildren(...): Encountered two children with the same key, `5:1:$`. Child keys must be unique; when two children share a key, only the first child will be used.
next_1 | in head (created by Head)
next_1 | in Head (at _document.js?entry:27)
next_1 | in html (at _document.js?entry:26)
next_1 | in MyDocument
As you can see in the logs, 2 styles elements have empty string keys. I’m 100% sure why, but I think these are caused by multiple calls to injectGlobal
.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oh. Right. I think I know what this is now
@geelen tested it out today and it’s fixed for me! Thanks 😃