Skip to content

Commit a8daa02

Browse files
authored
Merge pull request #4083 from cul/issue-4082-use_structuredClone
Replace JSON.parse(JSON.stringify(json)) with structuredClone
2 parents 2c36516 + 3032bc5 commit a8daa02

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

__tests__/src/selectors/manifests.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ describe('getManifestSearchService', () => {
506506
});
507507

508508
it('supports v1 of the search spec', () => {
509-
const v1 = JSON.parse(JSON.stringify(manifestFixtureFg165hz3589));
509+
const v1 = structuredClone(manifestFixtureFg165hz3589);
510510
v1.service[0].profile = 'http://iiif.io/api/search/1/search';
511511
const state = { manifests: { x: { json: v1 } } };
512512
expect(getManifestSearchService(state, { manifestId: 'x' }).id).toEqual('https://contentsearch.stanford.edu/fg165hz3589/search');
@@ -525,7 +525,7 @@ describe('getManifestAutocompleteService', () => {
525525
});
526526

527527
it('supports v1 of the search spec', () => {
528-
const v1 = JSON.parse(JSON.stringify(manifestFixtureFg165hz3589));
528+
const v1 = structuredClone(manifestFixtureFg165hz3589);
529529
v1.service[0].profile = 'http://iiif.io/api/search/1/search';
530530
v1.service[0].service.profile = 'http://iiif.io/api/search/1/autocomplete';
531531
const state = { manifests: { x: { json: v1 } } };

src/state/selectors/manifests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { getConfig } from './config';
99
/** */
1010
function createManifestoInstance(json, locale) {
1111
if (!json) return undefined;
12-
// Use JSON stringify/parse to create a deep copy and prevent Manifesto from mutating the json
13-
const manifestoObject = Utils.parseManifest(JSON.parse(JSON.stringify(json)), locale ? { locale } : undefined);
12+
// Use structuredClone to create a deep copy and prevent Manifesto from mutating the json
13+
const manifestoObject = Utils.parseManifest(structuredClone(json), locale ? { locale } : undefined);
1414
// Local patching of Manifesto so that when its a Collection, it behaves similarly
1515
if (typeof manifestoObject.getSequences != 'function') {
1616
manifestoObject.getSequences = () => [];

0 commit comments

Comments
 (0)