From d389beeb4b6ee02c9545d7ebe2a4e81fd951dc6e Mon Sep 17 00:00:00 2001 From: Nik Date: Tue, 31 Dec 2024 13:47:33 +0000 Subject: [PATCH] Lazy load prism (#136) Signed-off-by: Nik Nasr --- libs/ui/api/src/lib/API.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/libs/ui/api/src/lib/API.tsx b/libs/ui/api/src/lib/API.tsx index 1a6ed8ac..269e8d06 100644 --- a/libs/ui/api/src/lib/API.tsx +++ b/libs/ui/api/src/lib/API.tsx @@ -1,18 +1,21 @@ // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-nocheck import { lazy, useId } from 'react'; -import { Prism } from 'prism-react-renderer'; if (typeof window !== 'undefined') { - (window as any).Prism = Prism; + import('prism-react-renderer'); import('@stoplight/json-schema-viewer'); } -const JsonSchemaViewerInner = lazy(() => - import('@stoplight/json-schema-viewer').then((module) => ({ - default: module.JsonSchemaViewer, - })) -); +const JsonSchemaViewerInner = lazy(() => { + return import('prism-react-renderer').then((module) => { + (window as any).Prism = module.Prism; + + return import('@stoplight/json-schema-viewer').then((module) => ({ + default: module.JsonSchemaViewer, + })); + }); +}); export const API = ({ apiDescriptionDocument,