fix: monkey patch Client.call to return plain objects and avoid nextjs serialization error

This commit is contained in:
Carlos (Almeira) 2026-07-09 23:37:12 -05:00
parent b9f74a8c87
commit cd6a91ba9a
2 changed files with 26 additions and 0 deletions

View File

@ -10,6 +10,19 @@ if (typeof console !== 'undefined' && !(console as any)._appwritePatchedServer)
}
originalWarn(...args);
};
// Monkey-patch Client.prototype.call to always return plain objects
const originalCall = Client.prototype.call;
if (originalCall) {
Client.prototype.call = async function (this: any, ...args: any[]) {
const res = await originalCall.apply(this, args);
if (res && typeof res === 'object') {
return JSON.parse(JSON.stringify(res));
}
return res;
};
}
(console as any)._appwritePatchedServer = true;
}

View File

@ -9,6 +9,19 @@ if (typeof console !== 'undefined' && !(console as any)._appwritePatchedClient)
}
originalWarn(...args);
};
// Monkey-patch Client.prototype.call to always return plain objects
const originalCall = Client.prototype.call;
if (originalCall) {
Client.prototype.call = async function (this: any, ...args: any[]) {
const res = await originalCall.apply(this, args);
if (res && typeof res === 'object') {
return JSON.parse(JSON.stringify(res));
}
return res;
};
}
(console as any)._appwritePatchedClient = true;
}