Skip to content

Commit 2da76f9

Browse files
committed
fix(client): load assets relative using window.location
Fixes #112
1 parent c6c5f7d commit 2da76f9

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

packages/client/App.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ useTitle(`${website.replace(/https?:\/\/(www.)?/, '')} | Unlighthouse`)
220220
/>
221221
</div>
222222
</div>
223-
<div class="w-full min-w-1500px 2xl:(max-h-[calc(100vh-100px)]) lg:max-h-[calc(100vh-205px)] sm:max-h-[calc(100vh-220px)] max-h-[calc(100vh-250px)]">
223+
<div class="w-full min-w-1500px pr-3 overflow-y-auto 2xl:(max-h-[calc(100vh-100px)]) lg:max-h-[calc(100vh-205px)] sm:max-h-[calc(100vh-220px)] max-h-[calc(100vh-250px)]">
224224
<div v-if="Object.values(searchResults).length === 0" class="px-4 py-3">
225225
<template v-if="searchText">
226226
<p class="mb-2">

packages/client/components/Cell/CellImageOutline.vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script setup lang="ts">
22
import type { UnlighthouseColumn, UnlighthouseRouteReport } from '@unlighthouse/core/src'
3+
import { resolveArtifactPath } from '../../logic'
34
45
const props = defineProps<{
56
item: any
@@ -71,7 +72,7 @@ onMounted(() => {
7172
height: img.naturalHeight,
7273
}
7374
}
74-
img.src = `${props.report.artifactUrl}/full-screenshot.jpeg`
75+
img.src = resolveArtifactPath(props.report, '/full-screenshot.jpeg')
7576
})
7677
7778
const styles = computed(() => {
@@ -104,7 +105,7 @@ const styles = computed(() => {
104105
backgroundPositionY: `${-(positions.screenshot.top * zoomFactor)}px`,
105106
backgroundPositionX: `${-(positions.screenshot.left * zoomFactor)}px`,
106107
backgroundSize: `${screenshot.value.width * zoomFactor}px ${screenshot.value.height * zoomFactor}px`,
107-
backgroundImage: `url('${props.report.artifactUrl}/full-screenshot.jpeg')`,
108+
backgroundImage: `url('${resolveArtifactPath(props.report, '/full-screenshot.jpeg')}')`,
108109
}
109110
110111
const marker = {

packages/client/components/Cell/CellRouteName.vue

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts" setup>
22
import type { UnlighthouseColumn, UnlighthouseRouteReport } from '@unlighthouse/core'
3-
import { apiUrl, categories, device, iframeModalUrl, isModalOpen, isOffline } from '../../logic'
3+
import { apiUrl, categories, device, iframeModalUrl, isModalOpen, isOffline, resolveArtifactPath } from '../../logic'
44
55
const props = defineProps<{
66
report: UnlighthouseRouteReport
@@ -40,12 +40,12 @@ const thumbnail = computed(() => {
4040
const mobileProps = device === 'mobile' ? { class: 'w-68px h-112px' } : { class: 'h-82px w-112px' }
4141
if (categories.includes('performance')) {
4242
return {
43-
src: `${props.report.artifactUrl}/screenshot.jpeg`,
43+
src: resolveArtifactPath(props.report, '/screenshot.jpeg'),
4444
...mobileProps,
4545
}
4646
}
4747
return {
48-
src: `${props.report.artifactUrl}/full-screenshot.jpeg`,
48+
src: resolveArtifactPath(props.report, '/full-screenshot.jpeg'),
4949
...mobileProps,
5050
}
5151
})
@@ -81,6 +81,6 @@ const thumbnail = computed(() => {
8181
</div>
8282
</div>
8383
<teleport v-if="isModalOpen && showingModal" to="#modal-portal">
84-
<img :src="`${report.artifactUrl}/full-screenshot.jpeg`" alt="full screenshot" class="mx-auto">
84+
<img :src="resolveArtifactPath(props.report, '/full-screenshot.jpeg')" alt="full screenshot" class="mx-auto">
8585
</teleport>
8686
</template>

packages/client/logic/state.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import CellScoreSingle from '../components/Cell/CellScoreSingle.vue'
66
import CellScoresOverview from '../components/Cell/CellScoresOverview.vue'
77
import { useFetch } from './fetch'
88
import { sorting } from './search'
9-
import { categories, columns, isStatic, wsUrl } from './static'
9+
import { categories, columns, isStatic, resolveArtifactPath, wsUrl } from './static'
1010

1111
export const activeTab = ref(0)
1212

@@ -24,7 +24,7 @@ export function openDebugModal() {
2424
isDebugModalOpen.value = true
2525
}
2626
export function openLighthouseReportIframeModal(report: UnlighthouseRouteReport, tab?: string) {
27-
const path = `${report.artifactUrl}/lighthouse.html`
27+
const path = resolveArtifactPath(report, '/lighthouse.html')
2828
iframeModalUrl.value = `${path}${tab ? `#${tab}` : ''}`
2929
isDebugModalOpen.value = false
3030
isModalOpen.value = true

packages/client/logic/static.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { UnlighthouseRouteReport } from '@unlighthouse/core'
12
// pull out client accessible options
23
import MdiAccessibility from '~icons/mdi/accessibility'
34
import MdiCellphone from '~icons/mdi/cellphone'
@@ -7,7 +8,7 @@ import MdiViewDashboard from '~icons/mdi/view-dashboard'
78
import MdiWeb from '~icons/mdi/web'
89
import MdiWorld from '~icons/mdi/world'
910
import { startCase } from 'lodash-es'
10-
import { $URL } from 'ufo'
11+
import { $URL, joinURL } from 'ufo'
1112
import CellColorContrast from '../components/Cell/CellColorContrast.vue'
1213
import CellImage from '../components/Cell/CellImage.vue'
1314
import CellImageIssues from '../components/Cell/CellImageIssues.vue'
@@ -41,6 +42,11 @@ const {
4142

4243
export const isStatic = window.__unlighthouse_static
4344

45+
export function resolveArtifactPath(report: UnlighthouseRouteReport, file: string) {
46+
const withoutBase = report.artifactUrl.replace(basePath, '')
47+
return joinURL(window.location.pathname, withoutBase, file) // dynamic base
48+
}
49+
4450
export { apiUrl, basePath, device, dynamicSampling, groupRoutesKey, lighthouseOptions, throttle, wsUrl }
4551

4652
export const website = new $URL(site).origin

0 commit comments

Comments
 (0)