Skip to content

Commit

Permalink
Fix data being leaked due to app page title (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
Macludde authored Feb 17, 2025
1 parent a72be60 commit 7a109f3
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
10 changes: 4 additions & 6 deletions src/lib/components/nav/SetPageTitle.svelte
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<script lang="ts">
import { pageTitle } from "$lib/stores/pageTitle";
// import { onDestroy } from "svelte";
import { getContext } from "svelte";
import type { Writable } from "svelte/store";
/**
* The title of the page as shown in the browser tab.
* Undefined will set the title to "D-sektionen".
*/
export let title: string | undefined = undefined;
// let pageTitleBefore = $pageTitle;
// onDestroy(() => {
// $pageTitle = pageTitleBefore;
// });
let pageTitle = getContext<Writable<string>>("pageTitle");
$pageTitle = title ?? "D-sektionen";
$: $pageTitle = title ?? "D-sektionen";
</script>

<svelte:head>
Expand Down
3 changes: 0 additions & 3 deletions src/lib/stores/pageTitle.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/routes/(app)/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script lang="ts">
import GlobalAlert from "$lib/components/GlobalAlert.svelte";
import AppNotificationTokenHandler from "$lib/components/utils/AppNotificationTokenHandler.svelte";
import AppUnreadNotificationHandler from "$lib/components/utils/AppUnreadNotificationHandler.svelte";
import { languageTag } from "$paraglide/runtime";
import "dayjs/locale/sv";
import AppBottomNav from "../AppBottomNav.svelte";
Expand All @@ -8,8 +10,6 @@
import Footer from "../Footer.svelte";
import Navbar from "../Navbar.svelte";
import Toast from "../Toast.svelte";
import AppUnreadNotificationHandler from "$lib/components/utils/AppUnreadNotificationHandler.svelte";
import AppNotificationTokenHandler from "$lib/components/utils/AppNotificationTokenHandler.svelte";
export let data;
</script>
Expand Down
5 changes: 4 additions & 1 deletion src/routes/(nollning)/nollning/PostRevealHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import LoadingButton from "$lib/components/LoadingButton.svelte";
import NavIcon from "$lib/components/NavIcon.svelte";
import NotificationModal from "$lib/components/NotificationModal.svelte";
import { pageTitle } from "$lib/stores/pageTitle";
import { i18n } from "$lib/utils/i18n";
import { signIn } from "@auth/sveltekit/client";
import NotificationBell from "../../NotificationBell.svelte";
Expand All @@ -12,6 +11,8 @@
import { appBottomNavRoutes, getPostRevealRoute, getRoutes } from "./routes";
import type { PostRevealLayoutData } from "./+layout.server";
import type { NotificationGroup } from "$lib/utils/notifications/group";
import { getContext } from "svelte";
import type { Writable } from "svelte/store";
$: routes = getRoutes();
$: bottomNavRoutes = appBottomNavRoutes(routes);
Expand All @@ -28,6 +29,8 @@
let notificationModal: HTMLDialogElement;
let notifications: NotificationGroup[] | undefined = undefined;
let pageTitle = getContext<Writable<string>>("pageTitle");
</script>

<NotificationModal
Expand Down
8 changes: 6 additions & 2 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
<script lang="ts">
import { i18n } from "$lib/utils/i18n";
import { ParaglideJS } from "@inlang/paraglide-js-adapter-sveltekit";
import "../app.css";
import { languageTag } from "$paraglide/runtime";
import { ParaglideJS } from "@inlang/paraglide-js-adapter-sveltekit";
import dayjs from "dayjs";
import "../app.css";
/* Recommended for fraud detection */
import "@stripe/stripe-js";
import { setContext } from "svelte";
import { writable } from "svelte/store";
export let data;
$: (() => {
const locale = languageTag();
dayjs.locale(locale);
})();
let pageTitle = writable("D-sektionen");
setContext("pageTitle", pageTitle);
</script>

<svelte:head>
Expand Down
5 changes: 4 additions & 1 deletion src/routes/AppHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import LoadingButton from "$lib/components/LoadingButton.svelte";
import NavIcon from "$lib/components/NavIcon.svelte";
import NotificationModal from "$lib/components/NotificationModal.svelte";
import { pageTitle } from "$lib/stores/pageTitle";
import { i18n } from "$lib/utils/i18n";
import type { NotificationGroup } from "$lib/utils/notifications/group";
import { signIn } from "@auth/sveltekit/client";
import type { GlobalAppLoadData } from "./(app)/+layout.server";
import NotificationBell from "./NotificationBell.svelte";
import { appBottomNavRoutes, getRoutes } from "./routes";
import { getContext } from "svelte";
import type { Writable } from "svelte/store";
$: pageData = $page.data as typeof $page.data & GlobalAppLoadData;
$: notificationsPromise = pageData["notificationsPromise"];
Expand All @@ -21,6 +22,8 @@
let notificationModal: HTMLDialogElement;
let notifications: NotificationGroup[] | undefined = undefined;
let pageTitle = getContext<Writable<string>>("pageTitle");
</script>

<header
Expand Down

0 comments on commit 7a109f3

Please sign in to comment.