Skip to content

Commit a1b2c6e

Browse files
committed
- Added some checks when using window to prevent errors with SSR.
1 parent b91be5e commit a1b2c6e

File tree

5 files changed

+36
-24
lines changed

5 files changed

+36
-24
lines changed

resources/js/Layouts/AuthenticatedLayout.vue

+2
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ const isOnboarding = () => {
319319
};
320320
321321
const getQueryStatus = () => {
322+
if (isServer) return;
323+
322324
return new URLSearchParams(window.location.search).get('status');
323325
};
324326

resources/js/Pages/Dashboard.vue

+10-8
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,18 @@ const isDarkMode = ref(false);
138138
onMounted(() => {
139139
isClient.value = true;
140140
141-
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
142-
isDarkMode.value = e.matches;
143-
chartOptions.value = {
144-
title: {
145-
style: {
146-
color: e.matches ? '#a3a3a3' : '#0a0a0a',
141+
if (isClient.value) {
142+
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
143+
isDarkMode.value = e.matches;
144+
chartOptions.value = {
145+
title: {
146+
style: {
147+
color: e.matches ? '#a3a3a3' : '#0a0a0a',
148+
}
147149
}
148150
}
149-
}
150-
});
151+
});
152+
}
151153
});
152154
153155
const series = ref([

resources/js/Pages/Student/Dashboard.vue

+10-8
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,18 @@ const isDarkMode = ref(false);
213213
onMounted(() => {
214214
isClient.value = true;
215215
216-
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
217-
isDarkMode.value = e.matches;
218-
chartOptions.value = {
219-
title: {
220-
style: {
221-
color: e.matches ? '#a3a3a3' : '#0a0a0a',
216+
if (isClient.value) {
217+
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
218+
isDarkMode.value = e.matches;
219+
chartOptions.value = {
220+
title: {
221+
style: {
222+
color: e.matches ? '#a3a3a3' : '#0a0a0a',
223+
}
222224
}
223225
}
224-
}
225-
});
226+
});
227+
}
226228
});
227229
228230
const series = ref([

resources/js/Pages/Teachers/Students/Create.vue

+4
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ const form = useForm({
123123
timezone: '',
124124
});
125125
126+
const isServer = typeof window === 'undefined'
127+
126128
const submit = () => {
127129
form.transform((data) => ({
128130
...data,
@@ -140,6 +142,8 @@ const isOnboarding = () => {
140142
};
141143
142144
const getQueryStatus = () => {
145+
if (isServer) return;
146+
143147
return new URLSearchParams(window.location.search).get('status');
144148
};
145149
</script>

resources/js/Pages/Teachers/Students/Show.vue

+10-8
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,18 @@ const handleTimeframeChange = () => {
204204
onMounted(() => {
205205
isClient.value = true;
206206
207-
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
208-
isDarkMode.value = e.matches;
209-
chartOptions.value = {
210-
title: {
211-
style: {
212-
color: e.matches ? '#a3a3a3' : '#0a0a0a',
207+
if (isClient.value) {
208+
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
209+
isDarkMode.value = e.matches;
210+
chartOptions.value = {
211+
title: {
212+
style: {
213+
color: e.matches ? '#a3a3a3' : '#0a0a0a',
214+
}
213215
}
214216
}
215-
}
216-
});
217+
});
218+
}
217219
});
218220
219221
const series = ref([

0 commit comments

Comments
 (0)