Skip to content

Commit 0d2d24f

Browse files
authored
fix: add polyfills / avoid using structuredClone (#915)
- polyfills for `at` and `withResolvers` - avoid using `structuredClone`, we can use `JSON.parse(JSON.stringify(..))` instead at that position makes the site work in more browsers closes #911
1 parent c8f62af commit 0d2d24f

File tree

7 files changed

+27
-2
lines changed

7 files changed

+27
-2
lines changed

apps/svelte.dev/src/hooks.client.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@sveltejs/site-kit/polyfills';

apps/svelte.dev/src/routes/(authed)/playground/[id]/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@
6969
7070
if (!hash && !saved) {
7171
repl?.set({
72-
// TODO make this munging unnecessary
73-
files: structuredClone(data.gist.components).map(munge)
72+
// TODO make this munging unnecessary (using JSON instead of structuredClone for better browser compat)
73+
files: JSON.parse(JSON.stringify(data.gist.components)).map(munge)
7474
});
7575
7676
modified = false;

packages/editor/src/lib/compile-worker/worker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import '@sveltejs/site-kit/polyfills';
12
import { parseTar } from 'tarparser';
23
import type { CompileResult } from 'svelte/compiler';
34
import type { ExposedCompilerOptions, File } from '../Workspace.svelte';

packages/repl/src/lib/workers/bundler/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import '@sveltejs/site-kit/polyfills';
12
import '../patch_window';
23
import { sleep } from '../../utils';
34
import { rollup } from '@rollup/browser';

packages/site-kit/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@
9898
"default": "./src/lib/nav/index.ts",
9999
"svelte": "./src/lib/nav/index.ts"
100100
},
101+
"./polyfills": {
102+
"default": "./src/lib/polyfills/index.ts"
103+
},
101104
"./icons/link.svg": "./src/lib/icons/link.svg",
102105
"./icons/search.svg": "./src/lib/icons/search.svg",
103106
"./search": {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Some polyfills for things used throughout the app for better browser compat
2+
3+
if (!Array.prototype.at) {
4+
Array.prototype.at = /** @param {number} index */ function (index) {
5+
return this[index >= 0 ? index : this.length + index];
6+
};
7+
}
8+
9+
if (!Promise.withResolvers) {
10+
Promise.withResolvers = function () {
11+
let resolve: any, reject: any;
12+
const promise = new Promise<any>((res, rej) => {
13+
resolve = res;
14+
reject = rej;
15+
});
16+
return { resolve, reject, promise };
17+
};
18+
}

packages/site-kit/src/lib/search/search.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import '@sveltejs/site-kit/polyfills';
12
import flexsearch, { type Index as FlexSearchIndex } from 'flexsearch';
23
import type { Block, BlockGroup } from './types';
34

0 commit comments

Comments
 (0)