From a1a0cfcce552049ea351f0899023f9afd81ced98 Mon Sep 17 00:00:00 2001 From: Shane Date: Wed, 21 May 2025 08:08:07 -0400 Subject: [PATCH] refactor(playground): use structuredClone --- .changeset/structured-playground-change.md | 4 ++++ packages/playground/src/schema/tempLocalJsonSchemaUtils.ts | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 .changeset/structured-playground-change.md diff --git a/.changeset/structured-playground-change.md b/.changeset/structured-playground-change.md new file mode 100644 index 0000000..4656ceb --- /dev/null +++ b/.changeset/structured-playground-change.md @@ -0,0 +1,4 @@ +--- +"@open-rpc/playground": patch +--- +Use structuredClone for deep copies. diff --git a/packages/playground/src/schema/tempLocalJsonSchemaUtils.ts b/packages/playground/src/schema/tempLocalJsonSchemaUtils.ts index c6021f4..402a74a 100644 --- a/packages/playground/src/schema/tempLocalJsonSchemaUtils.ts +++ b/packages/playground/src/schema/tempLocalJsonSchemaUtils.ts @@ -2,7 +2,7 @@ import localJsonSchema from './localJsonSchema.json'; // eslint-disable-next-line @typescript-eslint/no-explicit-any export function convertToLocalJsonSchema(schema: any): any { if (!schema) return schema; - const schemaCopy = JSON.parse(JSON.stringify(schema)); + const schemaCopy = structuredClone(schema); if (!schemaCopy.definitions) { schemaCopy.definitions = {}; @@ -13,13 +13,13 @@ export function convertToLocalJsonSchema(schema: any): any { const resolvedDefinitions: Record = {}; Object.entries(schemaCopy.definitions).forEach(([key, def]) => { - resolvedDefinitions[key] = JSON.parse(JSON.stringify(def)); + resolvedDefinitions[key] = structuredClone(def); }); // Process each definition from localJsonSchema Object.entries(localJsonSchema.definitions).forEach(([key, def]) => { // Deep clone the definition - resolvedDefinitions[key] = JSON.parse(JSON.stringify(def)); + resolvedDefinitions[key] = structuredClone(def); }); // Function to recursively replace "#" refs with inline schema