Lazy load OpenSheetMusicDisplay

This commit is contained in:
2024-11-30 10:42:59 +01:00
parent 570629737e
commit 26bcfc684a
2 changed files with 48 additions and 43 deletions

View File

@@ -0,0 +1 @@
export { OpenSheetMusicDisplay as default } from "opensheetmusicdisplay";

View File

@@ -1,13 +1,15 @@
import { AttachmentId, PieceId } from "common";
import { OpenSheetMusicDisplay } from "opensheetmusicdisplay";
import { useEffect, useRef } from "react";
import { lazy, useEffect, useRef } from "react";
import { useParams } from "react-router-dom";
import { client } from "../client";
import { useLoading } from "../loading";
// TODO: Lazy load `opensheetmusicdisplay` (don't bundle into main script).
export const Attachment = lazy(async () => {
export function Attachment() {
const { default: OpenSheetMusicDisplay } = await import("../opensheetmusicdisplay.ts");
return {
default: function Attachment() {
const params = useParams();
const pieceId = PieceId(params.pieceId!);
@@ -59,4 +61,6 @@ export function Attachment() {
}
return <div ref={containerRef} className="w-full h-full overflow-scroll sheet-music-display" />;
}
},
};
});