Skip to content

Commit

Permalink
Improved label extraction from the stack traces to handle components …
Browse files Browse the repository at this point in the history
…with numbers in their names (#2122)

* fix emotion label not being applied to components with numbers in name

* add changeset

* add numbers to Safari and Firefox regex

* Update .changeset/nasty-starfishes-retire.md

* Update .changeset/nasty-starfishes-retire.md

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
  • Loading branch information
dcastil and Andarist committed Nov 21, 2020
1 parent 3b41e94 commit 1ee3400
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-starfishes-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@emotion/react': patch
---

Improved label extraction from the stack traces to handle components with numbers in their names.
4 changes: 2 additions & 2 deletions packages/react/src/emotion-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ export const createEmotionProps = (type: React.ElementType, props: Object) => {
if (error.stack) {
// chrome
let match = error.stack.match(
/at (?:Object\.|Module\.|)(?:jsx|createEmotionProps).*\n\s+at (?:Object\.|)([A-Z][A-Za-z$]+) /
/at (?:Object\.|Module\.|)(?:jsx|createEmotionProps).*\n\s+at (?:Object\.|)([A-Z][A-Za-z0-9$]+) /
)
if (!match) {
// safari and firefox
match = error.stack.match(/.*\n([A-Z][A-Za-z$]+)@/)
match = error.stack.match(/.*\n([A-Z][A-Za-z0-9$]+)@/)
}
if (match) {
newProps[labelPropName] = sanitizeIdentifier(match[1])
Expand Down

0 comments on commit 1ee3400

Please sign in to comment.