Skip to content

Commit 08fd90e

Browse files
authored
Merge pull request #1077 from lgriffin/fix/runtime-bugs-and-types
Fix memory leaks, invalid HTML, and improve type safety
2 parents 77fcdd7 + f25d5bf commit 08fd90e

8 files changed

Lines changed: 33 additions & 18 deletions

File tree

src/lib/ui/learning-objects/content/Podcast.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
interface Props {
66
lo: Podcast;
7+
hideSummary?: boolean;
78
}
89
let { lo, hideSummary = false }: Props = $props();
910

src/lib/ui/learning-objects/layout/Cards.svelte

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<script lang="ts">
2-
import { onMount } from "svelte";
2+
import { onMount, onDestroy } from "svelte";
33
44
import type { Lo } from "@tutors/tutors-model-lib";
55
66
import Card from "$lib/ui/learning-objects/layout/Card.svelte";
7-
import { cubicOut } from "svelte/easing";
87
import { scale } from "svelte/transition";
98
import { scaleTransition } from "$lib/ui/navigators/animations";
109
import { currentCourse } from "$lib/runes.svelte";
@@ -19,8 +18,9 @@
1918
let ignorePin = "";
2019
let refresh = $state(true);
2120
let isLoaded = $state(false);
21+
let hasKeyListener = false;
2222
23-
function keypressInput(e: { key: string }) {
23+
function keypressInput(e: KeyboardEvent) {
2424
pinBuffer = pinBuffer.concat(e.key);
2525
if (pinBuffer === ignorePin) {
2626
los.forEach((lo) => {
@@ -35,9 +35,16 @@
3535
if (currentCourse?.value?.properties.ignorepin) {
3636
ignorePin = currentCourse?.value?.properties.ignorepin.toString();
3737
window.addEventListener("keydown", keypressInput);
38+
hasKeyListener = true;
3839
}
3940
isLoaded = true;
4041
});
42+
43+
onDestroy(() => {
44+
if (hasKeyListener) {
45+
window.removeEventListener("keydown", keypressInput);
46+
}
47+
});
4148
</script>
4249

4350
{#if los.length > 0 && isLoaded}

src/lib/ui/navigators/buttons/SearchButton.svelte

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<script lang="ts">
22
import { goto } from "$app/navigation";
3-
import { onDestroy } from "svelte";
3+
import { onMount, onDestroy } from "svelte";
44
import { currentCourse } from "$lib/runes.svelte";
55
import Icon from "$lib/ui/components/Icon.svelte";
66
import { t } from "$lib/services/i18n";
77
8-
let isSearching = sessionStorage.getItem("isSearching") === "true";
8+
let isSearching = $state(sessionStorage.getItem("isSearching") === "true");
99
let previousPage = "";
10+
let observer: MutationObserver | null = null;
1011
1112
const updateSearchState = () => {
1213
const currentPath = window.location.pathname;
@@ -37,17 +38,18 @@
3738
}
3839
};
3940
40-
const observer = new MutationObserver(checkForNavigation);
41-
observer.observe(document.body, {
42-
childList: true,
43-
subtree: true
41+
onMount(() => {
42+
observer = new MutationObserver(checkForNavigation);
43+
observer.observe(document.body, {
44+
childList: true,
45+
subtree: true
46+
});
47+
window.addEventListener("popstate", updateSearchState);
48+
updateSearchState();
4449
});
4550
46-
window.addEventListener("popstate", updateSearchState);
47-
updateSearchState();
48-
4951
onDestroy(() => {
50-
observer.disconnect();
52+
observer?.disconnect();
5153
window.removeEventListener("popstate", updateSearchState);
5254
});
5355
</script>

src/routes/(auth)/auth/[courseid]/+page.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<script lang="ts">
22
import SigninWithGithub from "../SigninWithGithub.svelte";
3+
import type { PageData } from "./$types";
34
45
interface Props {
5-
data: any;
6+
data: PageData;
67
}
78
let { data }: Props = $props();
89
</script>

src/routes/(course-reader)/course/[courseid]/+page.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<script lang="ts">
22
import Composite from "$lib/ui/learning-objects/structure/Composite.svelte";
3+
import type { PageData } from "./$types";
34
45
interface Props {
5-
data: any;
6+
data: PageData;
67
}
78
let { data }: Props = $props();
89
</script>

src/routes/(course-reader)/llm/[courseid]/+page.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
import { currentCourse } from "$lib/runes.svelte";
44
import { convertMdToHtml } from "@tutors/tutors-model-lib";
55
import SecondaryNavigator from "$lib/ui/navigators/SecondaryNavigator.svelte";
6+
import type { PageData } from "./$types";
67
import { sanitizeHtml } from "$lib/utils/sanitize";
78
89
interface Props {
9-
data: any;
10+
data: PageData;
1011
}
1112
let { data }: Props = $props();
1213

src/routes/(course-reader)/time/[courseid]/+page.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
import HeatMaps from "./HeatMaps.svelte";
55
import Tables from "./Tables.svelte";
66
import SecondaryNavigator from "$lib/ui/navigators/SecondaryNavigator.svelte";
7+
import type { PageData } from "./$types";
78
import log from "$lib/services/logger";
89
910
interface Props {
10-
data: any;
11+
data: PageData;
1112
}
1213
let { data }: Props = $props();
1314

src/routes/(live)/catalogue/+page.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import { catalogueService } from "$lib/services/community";
33
import Catalogue from "$lib/ui/time/Catalogue.svelte";
44
import { onMount } from "svelte";
5+
import type { PageData } from "./$types";
56
67
interface Props {
7-
data: any;
8+
data: PageData;
89
}
910
let { data }: Props = $props();
1011
let totalModules = $state(0);

0 commit comments

Comments
 (0)