Skip to content

Commit 68c305f

Browse files
committed
fix: onDestroy when switching to /post/audience page for future.
1 parent 653e65f commit 68c305f

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

  • platforms/pictique/client/src/routes/(protected)/post

platforms/pictique/client/src/routes/(protected)/post/+page.svelte

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<script lang="ts">
2-
import { goto } from '$app/navigation';
2+
import { beforeNavigate, goto } from '$app/navigation';
33
import { SettingsTile, UploadedPostView } from '$lib/fragments';
44
import { audience, uploadedImages } from '$lib/store/store.svelte';
55
import { createPost } from '$lib/stores/posts';
66
import { Button, Textarea } from '$lib/ui';
77
import { revokeImageUrls } from '$lib/utils';
88
import { formatSize, validateFileSize } from '$lib/utils/fileValidation';
9-
import { onDestroy } from 'svelte';
109
1110
const MAX_TOTAL_SIZE = 5 * 1024 * 1024; // 5MB total
1211
const MAX_FILE_SIZE = 1 * 1024 * 1024; // 1MB per individual image
@@ -58,10 +57,12 @@
5857
input.value = '';
5958
};
6059
61-
onDestroy(() => {
62-
if (uploadedImages.value) {
63-
revokeImageUrls(uploadedImages.value);
64-
uploadedImages.value = null;
60+
beforeNavigate(({ to }) => {
61+
if (!to?.url.pathname.startsWith('/post')) {
62+
if (uploadedImages.value) {
63+
revokeImageUrls(uploadedImages.value);
64+
uploadedImages.value = null;
65+
}
6566
}
6667
});
6768

0 commit comments

Comments
 (0)