Skip to content

Commit

Permalink
Merge pull request #3830 from jupyter-widgets/revert-3689-patch-1
Browse files Browse the repository at this point in the history
Reverts #3689 and #3738 back to the original working codebase
  • Loading branch information
ibdafna authored Sep 12, 2023
2 parents 689bc46 + dc7ffe6 commit 2c76d22
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions packages/base/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ 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;

/**
* Replace model ids with models recursively.
*/
Expand Down Expand Up @@ -572,21 +565,12 @@ export class WidgetModel extends Backbone.Model {
JSONExt.emptyObject;
for (const k of Object.keys(state)) {
try {
const keySerializers = serializers[k] || JSONExt.emptyObject;
let { serialize } = keySerializers;

if (serialize == null && keySerializers.deserialize === unpack_models) {
// handle https://github.com/jupyter-widgets/ipywidgets/issues/3735
serialize = deepcopyJSON;
}

if (serialize) {
state[k] = serialize(state[k], this);
if (serializers[k] && serializers[k].serialize) {
state[k] = serializers[k].serialize!(state[k], this);
} else {
// the default serializer just deep-copies the object
state[k] = deepcopy(state[k]);
state[k] = JSON.parse(JSON.stringify(state[k]));
}

if (state[k] && state[k].toJSON) {
state[k] = state[k].toJSON();
}
Expand Down

0 comments on commit 2c76d22

Please sign in to comment.