From 83376515d042cb603ce3b17602246aeb8a920132 Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Tue, 4 Jun 2024 15:35:06 +0100 Subject: [PATCH 1/4] Older versions of Safari 16 don't support lookbehind assertions - https://caniuse.com/js-regexp-lookbehind --- packages/rrweb-snapshot/src/css.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/rrweb-snapshot/src/css.ts b/packages/rrweb-snapshot/src/css.ts index 220e1a1fce..95a312ce26 100644 --- a/packages/rrweb-snapshot/src/css.ts +++ b/packages/rrweb-snapshot/src/css.ts @@ -432,8 +432,8 @@ export function parse(css: string, options: ParserOptions = {}): Stylesheet { whitespace(); } - // Use match logic from https://github.com/NxtChg/pieces/blob/3eb39c8287a97632e9347a24f333d52d916bc816/js/css_parser/css_parse.js#L46C1-L47C1 - const m = match(/^(((? Date: Tue, 4 Jun 2024 15:50:23 +0100 Subject: [PATCH 2/4] Refactor to show the similarity between these two regexes --- packages/rrweb-snapshot/src/css.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/rrweb-snapshot/src/css.ts b/packages/rrweb-snapshot/src/css.ts index 95a312ce26..7aeb0d8a3d 100644 --- a/packages/rrweb-snapshot/src/css.ts +++ b/packages/rrweb-snapshot/src/css.ts @@ -424,6 +424,17 @@ export function parse(css: string, options: ParserOptions = {}): Stylesheet { * Parse selector. */ + // originally from https://github.com/NxtChg/pieces/blob/3eb39c8287a97632e9347a24f333d52d916bc816/js/css_parser/css_parse.js#L46C1-L47C1 + const selectorMatcher = new RegExp( + '^((' + + [ + /[^\\]"(?:\\"|[^"])*"/.source, // consume any quoted parts (checking that the double quote isn't itself escaped) + /[^\\]'(?:\\'|[^'])*'/.source, // same but for single quotes + '[^{]', + ].join('|') + + ')+)', + ); + function selector() { whitespace(); while (css[0] == '}') { @@ -432,8 +443,7 @@ export function parse(css: string, options: ParserOptions = {}): Stylesheet { whitespace(); } - // originally from https://github.com/NxtChg/pieces/blob/3eb39c8287a97632e9347a24f333d52d916bc816/js/css_parser/css_parse.js#L46C1-L47C1 - const m = match(/^(([^\\]"(?:\\"|[^"])*"|[^\\]'(?:\\'|[^'])*'|[^{])+)/); + const m = match(selectorMatcher); if (!m) { return; } @@ -869,8 +879,8 @@ export function parse(css: string, options: ParserOptions = {}): Stylesheet { name + '\\s*((?:' + [ - '[^\\\\]"(?:\\\\"|[^"])*"', // consume any quoted parts (checking that the double quote isn't itself escaped) - "[^\\\\]'(?:\\\\'|[^'])*'", // same but for single quotes + /[^\\]"(?:\\"|[^"])*"/.source, // consume any quoted parts (checking that the double quote isn't itself escaped) + /[^\\]'(?:\\'|[^'])*'/.source, // same but for single quotes '[^;]', ].join('|') + ')+);', From a411c7fe307d01383874eee612c599bb75bbd9c9 Mon Sep 17 00:00:00 2001 From: eoghanmurray Date: Tue, 4 Jun 2024 14:57:41 +0000 Subject: [PATCH 3/4] Apply formatting changes --- .changeset/silent-plants-perform.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/silent-plants-perform.md b/.changeset/silent-plants-perform.md index b87aaa908c..1b234ec2a0 100644 --- a/.changeset/silent-plants-perform.md +++ b/.changeset/silent-plants-perform.md @@ -1,5 +1,5 @@ --- -'rrweb': patch +"rrweb": patch --- Return early for child same origin frames From c7966b23877ae2bbab062f2adf6e3464c33c9c7e Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Tue, 4 Jun 2024 16:01:00 +0100 Subject: [PATCH 4/4] Create no-neg-lookbehind.md --- .changeset/no-neg-lookbehind.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/no-neg-lookbehind.md diff --git a/.changeset/no-neg-lookbehind.md b/.changeset/no-neg-lookbehind.md new file mode 100644 index 0000000000..f152328ed3 --- /dev/null +++ b/.changeset/no-neg-lookbehind.md @@ -0,0 +1,6 @@ +--- +"rrweb-snapshot": patch +"rrweb": patch +--- + +Replay: Replace negative lookbehind in regexes from css parser as it causes issues with Safari 16