|
1 | 1 | import { visit, SKIP } from 'unist-util-visit'
|
2 | 2 |
|
3 |
| -/** |
4 |
| - * `structuredClone` was added in Node 17 and onwards. |
5 |
| - * https://developer.mozilla.org/en-US/docs/Web/API/structuredClone#browser_compatibility |
6 |
| - * |
7 |
| - * At the time of writing, we use Node 18 in CI and in production, but |
8 |
| - * someone might be previewing locally with an older version so |
9 |
| - * let's make a quick polyfill. |
10 |
| - * We could add a specific (`js-core`) package for this polyfill, but it's |
11 |
| - * fortunately not necessary in this context because it's safe enough |
12 |
| - * clone by turning into a string and back again. |
13 |
| - */ |
14 |
| -function structuredClonePolyfill(obj) { |
15 |
| - if (typeof structuredClone !== 'undefined') { |
16 |
| - return structuredClone(obj) |
17 |
| - } else { |
18 |
| - // Note, that this naive clone would turn Date objects into strings. |
19 |
| - // So don't use this polyfill if certain values aren't primitives |
20 |
| - // that JSON.parse can handle. |
21 |
| - return JSON.parse(JSON.stringify(obj)) |
22 |
| - } |
23 |
| -} |
24 |
| - |
25 | 3 | // This number must match a width we're willing to accept in a dynamic
|
26 | 4 | // asset URL.
|
27 | 5 | // (note this is exported for the sake of end-to-end tests' assertions)
|
@@ -52,7 +30,7 @@ export default function rewriteAssetImgTags() {
|
52 | 30 | return (tree) => {
|
53 | 31 | visit(tree, matcher, (node) => {
|
54 | 32 | if (node.properties.src.endsWith('.png')) {
|
55 |
| - const copyPNG = structuredClonePolyfill(node) |
| 33 | + const copyPNG = structuredClone(node) |
56 | 34 |
|
57 | 35 | const sourceWEBP = {
|
58 | 36 | type: 'element',
|
|
0 commit comments