fix: handle cross-realm Promises in `hydratable` (#17284)

pull/17268/head
Rich Harris 5 days ago committed by GitHub
parent 617e179e68
commit 649d8572a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: handle cross-realm Promises in `hydratable`

@ -56,7 +56,7 @@ function encode(key, value, unresolved) {
let uid = 1;
entry.serialized = devalue.uneval(entry.value, (value, uneval) => {
if (value instanceof Promise) {
if (is_promise(value)) {
const p = value
.then((v) => `r(${uneval(v)})`)
.catch((devalue_error) =>
@ -90,6 +90,16 @@ function encode(key, value, unresolved) {
return entry;
}
/**
* @param {any} value
* @returns {value is Promise<any>}
*/
function is_promise(value) {
// we use this check rather than `instanceof Promise`
// because it works cross-realm
return Object.prototype.toString.call(value) === '[object Promise]';
}
/**
* @param {string} key
* @param {HydratableLookupEntry} a

Loading…
Cancel
Save