Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hungry-rules-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@emotion/sheet': patch
---

Prevent vendor-specific pseudo-elements from throwing errors when speedy = true
20 changes: 18 additions & 2 deletions packages/sheet/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,26 @@ export class StyleSheet {
// the big drawback is that the css won't be editable in devtools
sheet.insertRule(rule, sheet.cssRules.length)
} catch (e) {
/*
Unrecognized vendor-specific pseudo-selectors like -moz-*
or -webkit-* will throw a SyntaxError when parsed during
the insertRule() call. Since the failing selector(s) target
a different browser, these errors are safe to ignore.

All browsers seem to have slightly different error messages around
this case, making the detection just a little bit more difficult.
SyntaxError errors aren't surfacing frequently.
As long as the rule includes a left curly bracket marking
the beginning of a declaration block AND a vendor-specific
pseudo-selector, we can be almost certain that it is the reason
for the thrown SyntaxError.
*/
if (
isDevelopment &&
!/:(-moz-placeholder|-moz-focus-inner|-moz-focusring|-ms-input-placeholder|-moz-read-write|-moz-read-only|-ms-clear|-ms-expand|-ms-reveal){/.test(
rule
!(
e instanceof SyntaxError &&
/:-(webkit|moz|ms|o)-/.test(rule) &&
rule.indexOf('{') !== -1
)
) {
console.error(
Expand Down
Loading