Skip to content

Commit 6085201

Browse files
committed
WebSocketsPlugin: polyfill structureClone in Safari < 15
1 parent aadcbea commit 6085201

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/dev-server-core/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"dependencies": {
6161
"@types/koa": "^2.11.6",
6262
"@types/ws": "^7.4.0",
63+
"@ungap/structured-clone": "^1.2.0",
6364
"@web/parse5-utils": "^2.1.0",
6465
"chokidar": "^4.0.1",
6566
"clone": "^2.1.2",
@@ -82,6 +83,7 @@
8283
"@types/koa-etag": "^3.0.0",
8384
"@types/koa-static": "^4.0.1",
8485
"@types/parse5": "^6.0.1",
86+
"@types/ungap__structured-clone": "^1.2.0",
8587
"abort-controller": "^3.0.0",
8688
"express": "^4.18.2",
8789
"nanoid": "^3.1.25",

packages/dev-server-core/src/web-sockets/webSocketsPlugin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Plugin } from '../plugins/Plugin.js';
22
import { NAME_WEB_SOCKET_IMPORT, NAME_WEB_SOCKET_API } from './WebSocketsManager.js';
33
import { appendToDocument, isHtmlFragment } from '@web/parse5-utils';
4+
import structuredClonePolyfill from '@ungap/structured-clone';
45

56
export const webSocketScript = `<!-- injected by web-dev-server -->
67
<script type="module" src="${NAME_WEB_SOCKET_IMPORT}"></script>`;
@@ -40,7 +41,7 @@ export function webSocketsPlugin(): Plugin {
4041
}
4142
4243
export function stable (obj, replacer, spacer) {
43-
var target = structuredClone(obj)
44+
var target = ('structuredClone' in globalThis) ? structuredClone(obj) : structuredClonePolyfill(obj)
4445
var tmp = deterministicDecirc(target, '', [], undefined) || target
4546
var res
4647
if (replacerStack.length === 0) {

0 commit comments

Comments
 (0)