Emotion: ref is set to undefined when props.innerRef is undefined

Created on 13 Jun 2018  路  6Comments  路  Source: emotion-js/emotion

  • emotion version: 9.2.3
  • preact version: 8.2.9

When I styled Router from reach router, it set ref=undefined.
Preact passed the ref along as a prop: https://github.com/developit/preact/issues/1143
And then reach router crashed: https://github.com/reach/router/issues/73

Repo case in preact: https://codesandbox.io/s/n3mpmk2054
Works fine in react: https://codesandbox.io/s/887o6v4p9j

The cause is on https://github.com/emotion-js/emotion/blob/master/packages/create-emotion-styled/src/index.js#L136
While this isn't emotion's bug per se, it can prevent this bug by only setting ref when when props.innerRef is present.

All 6 comments

@Pyrolistical Thank you for reporting this!
As a quick fix, you can use shouldForwardProp to block ref.

@Ailrun that works! Thank you.

Workaround:

const Router = styled(UnstyledRouter, {
  shouldForwardProp: (key) => key !== 'ref'
})`
...
`

Reminder to do https://github.com/emotion-js/emotion/issues/655

Closing since this issue since a PR was merged into preact fixing this.

@mitchellhamilton Could you link the PR?

Great! Thx!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JustinTRoss picture JustinTRoss  路  26Comments

stolinski picture stolinski  路  37Comments

mitchellhamilton picture mitchellhamilton  路  82Comments

eXtreaL picture eXtreaL  路  29Comments

jfrolich picture jfrolich  路  29Comments