From a40544bc9e45b83feb95899d71e872ccbc98f70c Mon Sep 17 00:00:00 2001 From: Nate Rush Date: Thu, 11 May 2023 18:00:17 +0200 Subject: [PATCH 1/2] fix: fallback to lumino deepCopy rather than JSON.parse --- packages/base/src/widget.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/base/src/widget.ts b/packages/base/src/widget.ts index cfea6ef8fe..90cc6b79d6 100644 --- a/packages/base/src/widget.ts +++ b/packages/base/src/widget.ts @@ -34,12 +34,7 @@ import { KernelMessage } from '@jupyterlab/services'; */ const IPY_MODEL_ = 'IPY_MODEL_'; -/** - * A best-effort method for performing deep copies. - */ -const deepcopyJSON = (x: JSONValue) => JSON.parse(JSON.stringify(x)); - -const deepcopy = globalThis.structuredClone || deepcopyJSON; +const deepcopy = globalThis.structuredClone || JSONExt.deepCopy; /** * Replace model ids with models recursively. @@ -577,7 +572,7 @@ export class WidgetModel extends Backbone.Model { if (serialize == null && keySerializers.deserialize === unpack_models) { // handle https://github.com/jupyter-widgets/ipywidgets/issues/3735 - serialize = deepcopyJSON; + serialize = JSONExt.deepCopy; } if (serialize) { From 0c508399d033faf2b318b2d5f032cdad49482235 Mon Sep 17 00:00:00 2001 From: Nate Rush Date: Thu, 11 May 2023 18:20:00 +0200 Subject: [PATCH 2/2] fix: push deepclone function down to usage in seralize --- ipywidgets | 1 + packages/base/src/widget.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 160000 ipywidgets diff --git a/ipywidgets b/ipywidgets new file mode 160000 index 0000000000..511663a563 --- /dev/null +++ b/ipywidgets @@ -0,0 +1 @@ +Subproject commit 511663a56324cea5324f49a65ebe25e2f1b04d87 diff --git a/packages/base/src/widget.ts b/packages/base/src/widget.ts index 90cc6b79d6..743b0365a8 100644 --- a/packages/base/src/widget.ts +++ b/packages/base/src/widget.ts @@ -34,7 +34,6 @@ import { KernelMessage } from '@jupyterlab/services'; */ const IPY_MODEL_ = 'IPY_MODEL_'; -const deepcopy = globalThis.structuredClone || JSONExt.deepCopy; /** * Replace model ids with models recursively. @@ -579,6 +578,7 @@ export class WidgetModel extends Backbone.Model { state[k] = serialize(state[k], this); } else { // the default serializer just deep-copies the object + const deepcopy = globalThis.structuredClone || JSONExt.deepCopy; state[k] = deepcopy(state[k]); }