question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[v2] 2.0.0-17 SSR can contains conflicting keys

See original GitHub issue

Hi, 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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
geelencommented, May 16, 2017

Oh. Right. I think I know what this is now

1reaction
SBoudriascommented, May 23, 2017

@geelen tested it out today and it’s fixed for me! Thanks 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found