Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/olive-mangos-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: handle cross-realm Promises in `hydratable`
12 changes: 11 additions & 1 deletion packages/svelte/src/internal/server/hydratable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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
Expand Down
Loading