Skip to content

Commit 3d0d89c

Browse files
authored
fix: use postcss-safe-parser (#50)
1 parent 135afe5 commit 3d0d89c

File tree

5 files changed

+45
-7
lines changed

5 files changed

+45
-7
lines changed

CHANGELOG.md

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
## 0.0.7 - 2025-02-03
22

3-
4-
53
## 0.0.6 - 2025-02-01
64

75
## 0.0.5 - 2025-01-31

packages/rrweb-snapshot/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
"vitest": "^1.4.0"
6060
},
6161
"dependencies": {
62-
"postcss": "^8.4.38"
62+
"@types/postcss-safe-parser": "^5.0.4",
63+
"postcss": "^8.5.1",
64+
"postcss-safe-parser": "^7.0.1"
6365
}
6466
}

packages/rrweb-snapshot/src/rebuild.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { mediaSelectorPlugin, pseudoClassPlugin } from './css';
2+
import safeParser from 'postcss-safe-parser';
23
import {
34
type serializedNodeWithId,
45
type serializedElementNodeWithId,
@@ -67,7 +68,7 @@ export function adaptCssForReplay(cssText: string, cache: BuildCache): string {
6768
const ast: { css: string } = postcss([
6869
mediaSelectorPlugin,
6970
pseudoClassPlugin,
70-
]).process(cssText);
71+
]).process(cssText, { parser: safeParser });
7172
result = ast.css;
7273
} catch (error) {
7374
// on the replay side so should be ok to just log here

packages/rrweb-snapshot/test/rebuild.test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -271,16 +271,17 @@ ul li.specified c.\\:hover img {
271271
);
272272
});
273273

274-
it('handles exceptions from postcss when calling adaptCssForReplay', () => {
274+
it('safe parser handles exceptions from postcss when calling adaptCssForReplay', () => {
275275
const consoleWarnSpy = vi
276276
.spyOn(console, 'warn')
277277
.mockImplementation(() => {});
278278
// trigger CssSyntaxError by passing invalid css
279279
const cssText = 'a{';
280-
adaptCssForReplay(cssText, cache);
281-
expect(consoleWarnSpy).toHaveBeenLastCalledWith(
280+
const parsed = adaptCssForReplay(cssText, cache);
281+
expect(consoleWarnSpy).not.toHaveBeenLastCalledWith(
282282
'Failed to adapt css for replay',
283283
expect.any(Error),
284284
);
285+
expect(parsed).toBe('a{}');
285286
});
286287
});

yarn.lock

+36
Original file line numberDiff line numberDiff line change
@@ -2808,6 +2808,13 @@
28082808
dependencies:
28092809
"@types/node" "*"
28102810

2811+
"@types/postcss-safe-parser@^5.0.4":
2812+
version "5.0.4"
2813+
resolved "https://registry.yarnpkg.com/@types/postcss-safe-parser/-/postcss-safe-parser-5.0.4.tgz#2913271fb07e62b8829753e809f011be967d6652"
2814+
integrity sha512-5zGTm1jsW3j4+omgND1SIDbrZOcigTuxa4ihppvKbLkg2INUGBHV/fWNRSRFibK084tU3fxqZ/kVoSIGqRHnrQ==
2815+
dependencies:
2816+
postcss "^8.4.4"
2817+
28112818
"@types/[email protected]", "@types/prettier@^2.1.5":
28122819
version "2.7.3"
28132820
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.7.3.tgz#3e51a17e291d01d17d3fc61422015a933af7a08f"
@@ -7875,6 +7882,11 @@ nanoid@^3.3.7:
78757882
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.7.tgz#d0c301a691bc8d54efa0a2226ccf3fe2fd656bd8"
78767883
integrity sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==
78777884

7885+
nanoid@^3.3.8:
7886+
version "3.3.8"
7887+
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.8.tgz#b1be3030bee36aaff18bacb375e5cce521684baf"
7888+
integrity sha512-WNLf5Sd8oZxOm+TzppcYk8gVOgP+l58xNy58D0nbUnOxOWRWvlcCV4kUF7ltmI6PsrLl/BgKEyS4mqsGChFN0w==
7889+
78787890
nanoid@^4.0.0:
78797891
version "4.0.2"
78807892
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-4.0.2.tgz#140b3c5003959adbebf521c170f282c5e7f9fb9e"
@@ -8340,6 +8352,11 @@ picocolors@^1.0.0, picocolors@^1.0.1:
83408352
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.1.tgz#a8ad579b571952f0e5d25892de5445bcfe25aaa1"
83418353
integrity sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew==
83428354

8355+
picocolors@^1.1.1:
8356+
version "1.1.1"
8357+
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.1.1.tgz#3d321af3eab939b083c8f929a1d12cda81c26b6b"
8358+
integrity sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==
8359+
83438360
picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.2.3, picomatch@^2.3.1:
83448361
version "2.3.1"
83458362
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
@@ -8430,6 +8447,11 @@ postcss-safe-parser@^6.0.0:
84308447
resolved "https://registry.yarnpkg.com/postcss-safe-parser/-/postcss-safe-parser-6.0.0.tgz#bb4c29894171a94bc5c996b9a30317ef402adaa1"
84318448
integrity sha512-FARHN8pwH+WiS2OPCxJI8FuRJpTVnn6ZNFiqAM2aeW2LwTHWWmWgIyKC6cUo0L8aeKiF/14MNvnpls6R2PBeMQ==
84328449

8450+
postcss-safe-parser@^7.0.1:
8451+
version "7.0.1"
8452+
resolved "https://registry.yarnpkg.com/postcss-safe-parser/-/postcss-safe-parser-7.0.1.tgz#36e4f7e608111a0ca940fd9712ce034718c40ec0"
8453+
integrity sha512-0AioNCJZ2DPYz5ABT6bddIqlhgwhpHZ/l65YAYo0BCIn0xiDpsnTHz0gnoTGk0OXZW0JRs+cDwL8u/teRdz+8A==
8454+
84338455
postcss-scss@^4.0.9:
84348456
version "4.0.9"
84358457
resolved "https://registry.yarnpkg.com/postcss-scss/-/postcss-scss-4.0.9.tgz#a03c773cd4c9623cb04ce142a52afcec74806685"
@@ -8452,6 +8474,15 @@ postcss@^8.4.38:
84528474
picocolors "^1.0.0"
84538475
source-map-js "^1.2.0"
84548476

8477+
postcss@^8.4.4, postcss@^8.5.1:
8478+
version "8.5.1"
8479+
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.5.1.tgz#e2272a1f8a807fafa413218245630b5db10a3214"
8480+
integrity sha512-6oz2beyjc5VMn/KV1pPw8fliQkhBXrVn1Z3TVyqZxU8kZpzEKhBdmCFqI6ZbmGtamQvQGuU1sgPTk8ZrXDD7jQ==
8481+
dependencies:
8482+
nanoid "^3.3.8"
8483+
picocolors "^1.1.1"
8484+
source-map-js "^1.2.1"
8485+
84558486
preferred-pm@^3.0.0:
84568487
version "3.1.3"
84578488
resolved "https://registry.yarnpkg.com/preferred-pm/-/preferred-pm-3.1.3.tgz#4125ea5154603136c3b6444e5f5c94ecf90e4916"
@@ -9438,6 +9469,11 @@ source-map-js@^1.0.1, source-map-js@^1.2.0:
94389469
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.2.0.tgz#16b809c162517b5b8c3e7dcd315a2a5c2612b2af"
94399470
integrity sha512-itJW8lvSA0TXEphiRoawsCksnlf8SyvmFzIhltqAHluXd88pkCd+cXJVHTDwdCr0IzwptSm035IHQktUu1QUMg==
94409471

9472+
source-map-js@^1.2.1:
9473+
version "1.2.1"
9474+
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.2.1.tgz#1ce5650fddd87abc099eda37dcff024c2667ae46"
9475+
integrity sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==
9476+
94419477
[email protected], source-map-support@^0.5.6:
94429478
version "0.5.21"
94439479
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f"

0 commit comments

Comments
 (0)