From cfdcbbaebe331394a74b412a8ad7028fdb3ec761 Mon Sep 17 00:00:00 2001 From: Corey Alexander Date: Sat, 20 Jan 2024 18:09:17 -0500 Subject: [PATCH] Fix Deploys: Move all Logic from `load` to `onMount` (#80) Builds are currently failing with this error message Accessing url.searchParams during prerendering is forbidden. If you need to use it, ensure you are only doing so in the browser (for example in onMount). It was introduced in #79 This error is because we are trying to access url.searchParams in the load function and ALSO have preloading enabled. Since load gets called on the server to pre-render, it doesn't allow us to access url.searchParams since that can only be known in the browser But this must be new behavior, since it was working for us previously. I think it was working previously is because load was acting as a 'universal` loader and running both in the 'server' when preloading, and also in the client when mounting for the first time. kit.svelte.dev/docs/load#universal-vs-server-when-does-which-load-function-run I imagine the server load was getting an empty searchSet, but continuing to work. And then the client load correctly filled in the query param values But from reading the Changelog I can't find anything that seems obviously like it would have broken this behavior I do think this is a good change to prepare for v2, since it seems required there as well! --- .github/workflows/tests.yaml | 9 +++++ .node-version | 2 +- src/routes/(iframed)/+page.svelte | 41 +++++++++++++++------- src/routes/(iframed)/+page.ts | 21 ----------- src/routes/(iframed)/settings/+page.svelte | 4 ++- 5 files changed, 42 insertions(+), 35 deletions(-) delete mode 100644 src/routes/(iframed)/+page.ts diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index eec8367..be84e2c 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -32,3 +32,12 @@ jobs: - uses: actions/checkout@v3 - run: npm ci - run: npm run test:unit + + build: + name: npm run build + needs: [check] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: npm ci + - run: npm run build diff --git a/.node-version b/.node-version index 3c03207..4a1f488 100644 --- a/.node-version +++ b/.node-version @@ -1 +1 @@ -18 +18.17.1 diff --git a/src/routes/(iframed)/+page.svelte b/src/routes/(iframed)/+page.svelte index cf96df9..b535383 100644 --- a/src/routes/(iframed)/+page.svelte +++ b/src/routes/(iframed)/+page.svelte @@ -1,10 +1,12 @@
- {#if data.settingError} + {#if settingError}

To display a game you need to specify the ID in the URL.

@@ -76,15 +93,15 @@

{:else if $playbackState} - +
- {#if data.settings.title} -

{data.settings.title}

+ {#if settings.title} +

{settings.title}

{/if} - - {#if data.settings.showControls} - {#if data.settings.showScrubber} + + {#if settings.showControls} + {#if settings.showScrubber}
@@ -102,7 +119,7 @@
{/if}
- {#if data.settings.showScoreboard} + {#if settings.showScoreboard}
diff --git a/src/routes/(iframed)/+page.ts b/src/routes/(iframed)/+page.ts deleted file mode 100644 index c31686d..0000000 --- a/src/routes/(iframed)/+page.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { initWindowMessages } from "$lib/playback/messages"; -import { playbackState } from "$lib/playback/stores"; -import { loadSettingsWithURLOverrides } from "$lib/settings/stores"; -import { setTheme } from "$lib/theme"; - -import type { PageLoad } from "./$types"; - -export const load = (({ fetch, url }) => { - const settings = loadSettingsWithURLOverrides(url); - - setTheme(settings.theme); - - let settingError = true; - if (settings.game.length > 0 && settings.engine.length > 0) { - settingError = false; - playbackState.load(fetch, settings); - initWindowMessages(); - } - - return { settings, settingError }; -}) satisfies PageLoad; diff --git a/src/routes/(iframed)/settings/+page.svelte b/src/routes/(iframed)/settings/+page.svelte index 878128b..79e749e 100644 --- a/src/routes/(iframed)/settings/+page.svelte +++ b/src/routes/(iframed)/settings/+page.svelte @@ -7,7 +7,9 @@ { value: 18, text: "Fast" } ]; - function navigateBack() { + function navigateBack(e: MouseEvent) { + e.preventDefault(); + history.back(); }