Skip to content

Commit ed58f69

Browse files
authored
Dynamically import dependencies that are not critical to viewing the UI (#2001)
1 parent a62d5e0 commit ed58f69

File tree

6 files changed

+30
-15
lines changed

6 files changed

+30
-15
lines changed

photon-client/src/components/app/photon-3d-visualizer.vue

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
<script setup lang="ts">
22
import type { PhotonTarget } from "@/types/PhotonTrackingTypes";
3+
// @ts-expect-error Intellisense says these conflict with the dynamic imports below
4+
import type { Mesh, Object3D, PerspectiveCamera, Scene, WebGLRenderer } from "three";
5+
// @ts-expect-error Intellisense says these conflict with the dynamic imports below
6+
import type { TrackballControls } from "three/examples/jsm/controls/TrackballControls";
37
import { onBeforeUnmount, onMounted, watchEffect } from "vue";
4-
import {
8+
const {
59
ArrowHelper,
610
BoxGeometry,
711
Color,
812
ConeGeometry,
913
Mesh,
1014
MeshNormalMaterial,
11-
type Object3D,
1215
PerspectiveCamera,
1316
Quaternion,
14-
Scene,
1517
Vector3,
18+
Scene,
1619
WebGLRenderer
17-
} from "three";
18-
import { TrackballControls } from "three/examples/jsm/controls/TrackballControls";
20+
} = await import("three");
21+
const { TrackballControls } = await import("three/examples/jsm/controls/TrackballControls");
1922
2023
const props = defineProps<{
2124
targets: PhotonTarget[];
@@ -114,7 +117,7 @@ const resetCamThirdPerson = () => {
114117
}
115118
};
116119
117-
onMounted(() => {
120+
onMounted(async () => {
118121
scene = new Scene();
119122
camera = new PerspectiveCamera(75, 800 / 800, 0.1, 1000);
120123

photon-client/src/components/cameras/CameraCalibrationCard.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import { computed, ref } from "vue";
33
import { useCameraSettingsStore } from "@/stores/settings/CameraSettingsStore";
44
import { CalibrationBoardTypes, CalibrationTagFamilies, type VideoFormat } from "@/types/SettingTypes";
5-
import JsPDF from "jspdf";
6-
import { font as PromptRegular } from "@/assets/fonts/PromptRegular";
75
import MonoLogo from "@/assets/images/logoMono.png";
86
import CharucoImage from "@/assets/images/ChArUco_Marker8x8.png";
97
import PvSlider from "@/components/common/pv-slider.vue";
@@ -15,6 +13,8 @@ import { WebsocketPipelineType } from "@/types/WebsocketDataTypes";
1513
import { getResolutionString, resolutionsAreEqual } from "@/lib/PhotonUtils";
1614
import CameraCalibrationInfoCard from "@/components/cameras/CameraCalibrationInfoCard.vue";
1715
import { useSettingsStore } from "@/stores/settings/GeneralSettingsStore";
16+
const PromptRegular = import("@/assets/fonts/PromptRegular");
17+
const jspdf = import("jspdf");
1818
1919
const settingsValid = ref(true);
2020
@@ -88,10 +88,12 @@ const tooManyPoints = computed(
8888
() => useStateStore().calibrationData.imageCount * patternWidth.value * patternHeight.value > 700000
8989
);
9090
91-
const downloadCalibBoard = () => {
92-
const doc = new JsPDF({ unit: "in", format: "letter" });
91+
const downloadCalibBoard = async () => {
92+
const { jsPDF } = await jspdf;
93+
const { font } = await PromptRegular;
94+
const doc = new jsPDF({ unit: "in", format: "letter" });
9395
94-
doc.addFileToVFS("Prompt-Regular.tff", PromptRegular);
96+
doc.addFileToVFS("Prompt-Regular.tff", font);
9597
doc.addFont("Prompt-Regular.tff", "Prompt-Regular", "normal");
9698
doc.setFont("Prompt-Regular");
9799
doc.setFontSize(12);

photon-client/src/components/dashboard/tabs/Map3DTab.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ const trackedTargets = computed<PhotonTarget[]>(() => useStateStore().currentPip
1616
</v-row>
1717
<v-row style="width: 100%">
1818
<v-col style="display: flex; align-items: center; justify-content: center">
19-
<photon3d-visualizer :targets="trackedTargets" />
19+
<Suspense>
20+
<!-- Allows us to import three js when it's actually needed -->
21+
<photon3d-visualizer :targets="trackedTargets" />
22+
23+
<template #fallback> Loading... </template>
24+
</Suspense>
2025
</v-col>
2126
</v-row>
2227
</div>

photon-client/src/components/settings/ApriltagControlCard.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<script setup lang="ts">
22
import { useSettingsStore } from "@/stores/settings/GeneralSettingsStore";
3-
import { Euler, Quaternion as ThreeQuat } from "three";
43
import type { Quaternion } from "@/types/PhotonTrackingTypes";
54
import { toDeg } from "@/lib/MathUtils";
5+
const { Euler, Quaternion: ThreeQuat } = await import("three");
66
77
const quaternionToEuler = (rot_quat: Quaternion): { x: number; y: number; z: number } => {
88
const quat = new ThreeQuat(rot_quat.X, rot_quat.Y, rot_quat.Z, rot_quat.W);

photon-client/src/plugins/vuetify.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import "vuetify/styles";
2-
import "@mdi/font/css/materialdesignicons.css";
2+
import("@mdi/font/css/materialdesignicons.css");
33
import type { ThemeDefinition } from "vuetify/lib/composables/theme";
44
import { createVuetify } from "vuetify";
55

photon-client/src/views/GeneralSettingsView.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import ApriltagControlCard from "@/components/settings/ApriltagControlCard.vue";
1515
<NetworkingCard />
1616
<ObjectDetectionCard v-if="useSettingsStore().general.supportedBackends.length > 0" />
1717
<LightingControlCard v-if="useSettingsStore().lighting.supported" />
18-
<ApriltagControlCard />
18+
<Suspense>
19+
<!-- Allows us to import three js when it's actually needed -->
20+
<ApriltagControlCard />
21+
22+
<template #fallback> Loading... </template>
23+
</Suspense>
1924
</div>
2025
</template>

0 commit comments

Comments
 (0)