Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverts #3689 and #3738 back to the original working codebase #3830

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading