Skip to content

Commit 649d857

Browse files
authored
fix: handle cross-realm Promises in hydratable (#17284)
1 parent 617e179 commit 649d857

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

.changeset/olive-mangos-march.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: handle cross-realm Promises in `hydratable`

packages/svelte/src/internal/server/hydratable.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function encode(key, value, unresolved) {
5656
let uid = 1;
5757

5858
entry.serialized = devalue.uneval(entry.value, (value, uneval) => {
59-
if (value instanceof Promise) {
59+
if (is_promise(value)) {
6060
const p = value
6161
.then((v) => `r(${uneval(v)})`)
6262
.catch((devalue_error) =>
@@ -90,6 +90,16 @@ function encode(key, value, unresolved) {
9090
return entry;
9191
}
9292

93+
/**
94+
* @param {any} value
95+
* @returns {value is Promise<any>}
96+
*/
97+
function is_promise(value) {
98+
// we use this check rather than `instanceof Promise`
99+
// because it works cross-realm
100+
return Object.prototype.toString.call(value) === '[object Promise]';
101+
}
102+
93103
/**
94104
* @param {string} key
95105
* @param {HydratableLookupEntry} a

0 commit comments

Comments
 (0)