Skip to content

Commit 241283d

Browse files
authored
Fix dashboard SSR (baserow#4778)
1 parent cec38a6 commit 241283d

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

web-frontend/modules/dashboard/middleware/dashboardLoading.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
1414
const fromDashboardId = parseIntOrNull(from?.params?.dashboardId)
1515
const differentDashboardId = fromDashboardId !== toDashboardId
1616

17-
if (!from || differentDashboardId) {
17+
// If it's the first page or the server side rendered page, then always put the
18+
// dashboard in the loading state for the correct animation.
19+
if (import.meta.server || !from || differentDashboardId) {
1820
await store.dispatch('dashboardApplication/setLoading', true)
1921
}
2022
})

web-frontend/modules/dashboard/pages/dashboard.vue

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div v-if="dashboard" class="dashboard-app">
2+
<div class="dashboard-app">
33
<DashboardHeader :dashboard="dashboard" />
44
<DashboardContent :dashboard="dashboard" />
55
</div>
@@ -16,15 +16,18 @@ import DashboardContent from '@baserow/modules/dashboard/components/DashboardCon
1616
1717
definePageMeta({
1818
layout: 'app',
19-
middleware: ['dashboardLoading'],
19+
middleware: [
20+
'settings',
21+
'authenticated',
22+
'workspacesAndApplications',
23+
'dashboardLoading',
24+
],
2025
})
2126
2227
const store = useStore()
2328
const route = useRoute()
24-
const router = useRouter()
2529
const { $hasPermission, $realtime } = useNuxtApp()
2630
27-
// Fetch dashboard data
2831
const {
2932
data,
3033
pending,
@@ -49,12 +52,15 @@ const {
4952
dashboard,
5053
}
5154
} catch (e) {
52-
console.error('Error loading dashboard:', e)
5355
throw createError({ statusCode: 404, message: 'Dashboard not found.' })
5456
}
5557
}
5658
)
5759
60+
if (fetchError.value) {
61+
throw fetchError.value
62+
}
63+
5864
const dashboard = computed(() => data.value?.dashboard)
5965
const workspace = computed(() => data.value?.workspace)
6066
@@ -71,7 +77,9 @@ onMounted(() => {
7177
forEditing,
7278
})
7379
74-
$realtime.subscribe('dashboard', { dashboard_id: dashboard.value.id })
80+
if (dashboard.value) {
81+
$realtime.subscribe('dashboard', { dashboard_id: dashboard.value.id })
82+
}
7583
})
7684
7785
// Cleanup

0 commit comments

Comments
 (0)