mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-05-22 11:55:15 -05:00
20 lines
1.2 KiB
TypeScript
20 lines
1.2 KiB
TypeScript
// Runtime polyfills that must execute before any other application module.
|
|
// Import this file first from `src/index.tsx`.
|
|
|
|
// ── BigInt.prototype.toJSON ───────────────────────────────────────────────────
|
|
// Protobuf-ES maps proto `int64`/`uint64` fields to native `BigInt`. Those
|
|
// land in Redux state (e.g. `ServerInfo_User.accountageSecs`,
|
|
// `Response_Register.deniedEndTime`, the outbound `cmdId`), and any consumer
|
|
// that JSON-stringifies state — notably the Redux DevTools browser
|
|
// extension, but also logging and error-boundary dumps — throws with
|
|
// "Do not know how to serialize a BigInt" because `BigInt.prototype` has no
|
|
// `toJSON`. Installing one globally makes `JSON.stringify` coerce
|
|
// `BigInt → string` instead of throwing. Coercion is lossy but only affects
|
|
// serialized representations; the in-memory Redux state still holds real
|
|
// `BigInt`s and every consumer reads them via the generated proto accessors.
|
|
(BigInt.prototype as unknown as { toJSON: () => string }).toJSON = function bigIntToJSON() {
|
|
return this.toString();
|
|
};
|
|
|
|
export {};
|