Skip to content

Commit 5dac2af

Browse files
committed
Polish frontend lifecycle and link safety
Move the home page's `onBeforeUnmount` registration out of the `onMounted` callback so Vue's setup-time hook contract is satisfied and the EventSource is reliably closed when the component unmounts. Surface fetch errors separately from missing resources on the profile and post detail pages so transient network failures no longer render the same "Not found" title as legitimate 404s. Add `rel="noopener noreferrer"` on the Fedify badge links opened with `target="_blank"`. fedify-dev#676 Assisted-by: Claude Code:claude-opus-4-7
1 parent 642ff70 commit 5dac2af

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

examples/nuxt/pages/index.vue

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157

158158
<div class="fedify-badge">
159159
Powered by
160-
<a href="https://fedify.dev" class="fedify-anchor" target="_blank">
160+
<a href="https://fedify.dev" class="fedify-anchor" target="_blank" rel="noopener noreferrer">
161161
Fedify
162162
</a>
163163
</div>
@@ -209,14 +209,17 @@ function formatDate(dateStr: string): string {
209209
});
210210
}
211211
212+
let eventSource: EventSource | null = null;
213+
212214
onMounted(() => {
213-
const eventSource = new EventSource("/api/events");
215+
eventSource = new EventSource("/api/events");
214216
eventSource.onmessage = () => {
215217
refresh();
216218
};
217-
onBeforeUnmount(() => {
218-
eventSource.close();
219-
});
219+
});
220+
221+
onBeforeUnmount(() => {
222+
eventSource?.close();
220223
});
221224
</script>
222225

examples/nuxt/pages/users/[identifier]/index.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
href="https://fedify.dev"
3838
class="fedify-anchor"
3939
target="_blank"
40+
rel="noopener noreferrer"
4041
>
4142
Fedify
4243
</a>
@@ -55,10 +56,12 @@
5556
const route = useRoute();
5657
const identifier = route.params.identifier as string;
5758
58-
const { data } = await useFetch(`/api/profile/${identifier}`);
59+
const { data, error } = await useFetch(`/api/profile/${identifier}`);
5960
6061
useHead({
61-
title: data.value
62+
title: error.value
63+
? "Error - Fedify Nuxt Example"
64+
: data.value
6265
? `${data.value.name} - Fedify Nuxt Example`
6366
: "Not Found - Fedify Nuxt Example",
6467
});

examples/nuxt/pages/users/[identifier]/posts/[id].vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ const route = useRoute();
4141
const identifier = route.params.identifier as string;
4242
const id = route.params.id as string;
4343
44-
const { data } = await useFetch(`/api/posts/${identifier}/${id}`);
44+
const { data, error } = await useFetch(`/api/posts/${identifier}/${id}`);
4545
4646
useHead({
47-
title: data.value
47+
title: error.value
48+
? "Error - Fedify Nuxt Example"
49+
: data.value
4850
? `Post - ${data.value.author.name} - Fedify Nuxt Example`
4951
: "Not Found - Fedify Nuxt Example",
5052
});

0 commit comments

Comments
 (0)