From 89c8d9a2392c8d60d577d21086ee83bbc30ad223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksa=20Siri=C5=A1ki?= <31509435+aleksasiriski@users.noreply.github.com> Date: Thu, 9 Nov 2023 19:13:39 +0100 Subject: [PATCH] fix: tracked down why it took 2x as much on SSR to load api --- package.json | 2 +- src/routes/search/+page.ts | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 43d8d6a4..babf04c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "prednjica", - "version": "0.3.0", + "version": "0.3.2", "private": true, "scripts": { "start": "node ./index.js", diff --git a/src/routes/search/+page.ts b/src/routes/search/+page.ts index f17a3e5e..9b758b88 100644 --- a/src/routes/search/+page.ts +++ b/src/routes/search/+page.ts @@ -1,7 +1,16 @@ import type { PageLoad } from './$types'; import { env } from '$env/dynamic/public'; -export const load: PageLoad = async ({ fetch, url }) => { +export const load: PageLoad = async ({ data, fetch, url }) => { + // this runs on SSR (+page.server.ts) + if (data != null) { + return { + query: data.query, + results: data.results + }; + } + + // this runs on CSR const q = url.searchParams.get('q'); if (q === null || q === '') { return {