We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 6547f84 + 5dceb78 commit ab7ea4bCopy full SHA for ab7ea4b
packages/base/src/widget.ts
@@ -524,6 +524,8 @@ export class WidgetModel extends Backbone.Model {
524
* binary array buffers.
525
*/
526
serialize(state: Dict<any>): JSONObject {
527
+ const deepcopy =
528
+ globalThis.structuredClone || ((x: any) => JSON.parse(JSON.stringify(x)));
529
const serializers =
530
(this.constructor as typeof WidgetModel).serializers || {};
531
for (const k of Object.keys(state)) {
@@ -532,7 +534,7 @@ export class WidgetModel extends Backbone.Model {
532
534
state[k] = serializers[k].serialize!(state[k], this);
533
535
} else {
536
// the default serializer just deep-copies the object
- state[k] = JSON.parse(JSON.stringify(state[k]));
537
+ state[k] = deepcopy(state[k]);
538
}
539
if (state[k] && state[k].toJSON) {
540
state[k] = state[k].toJSON();
0 commit comments