Questions tagged [sveltekit]

[SvelteKit](https://kit.svelte.dev/) is a framework for building fullstack web applications with the Svelte framework.

SvelteKit is a framework for building fullstack web applications with the Svelte framework.

2260 questions
11
votes
1 answer

Sveltekit and SSR

I need a bit of help understanding SSR in the context of sveltekit. I noticed that the load method is called both on the server and the client and I cannot wrap my head around this. I guess it is needed to initialize the state of the client-side…
jpfollenius
  • 16,456
  • 10
  • 90
  • 156
10
votes
2 answers

How to redirect to page in SvelteKit?

I have a page with content rendered from a SvelteKit store. If the store is invalid, a user needs do be redirected to the homepage. Unfortunately, I can't find a way to redirect a user even without checking any conditions, so let's focus on a…
Theo
  • 103
  • 1
  • 1
  • 6
10
votes
2 answers

Setting static asset cache TTL in SvelteKit

I am serving font and CSS files from /static using the default SvelteKit application template. I am using SvelteKit Node.js adapter. The default cache time-to-live (TTL) seems to be 4 hours for /static files. I am not sure if this is set by…
Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
10
votes
5 answers

How to update the page and query parameters in SvelteKit?

I have a page with a search field. If accessed with a query parameter (e.g. ?word=cat) the page should load with results present and the search field filled. If a search is done the results and the query parameters (browser history) should…
Steffen
  • 1,328
  • 3
  • 12
  • 29
10
votes
2 answers

How to access websocket in svelte?

I am trying to connect my svelte to my fastapi backend but I am getting this error…
yawad
  • 123
  • 1
  • 6
10
votes
2 answers

registering socket IO to vite for sveltekit

I have written a few apps using svelte and sapper and thought I would give sveltekit a go. All in all it works, but I am now running into the issue of registering a worker on ther server. Basically I am trying to add socket.io to my app because I…
munHunger
  • 2,572
  • 5
  • 34
  • 63
9
votes
1 answer

How to extend Locals interface in SvelteKit

The Svelte documentation shows how to set an element on locals in hooks: https://kit.svelte.dev/docs/hooks#server-hooks event.locals.user = await getUserInformation(event.cookies.get('sessionid')); If I try to extend the locals Object in TypeScript…
CordlessWool
  • 1,388
  • 4
  • 17
  • 35
9
votes
1 answer

Returnning the error page in Hooks / Sveltekit

The documentation seems a bit vague about showing the error page from Hooks. I am looking for a way to show the 404 page conditionally. export async function handle({ event, resolve }) { return new Response('This page does not exist.', {status:…
yongju lee
  • 564
  • 1
  • 4
  • 16
9
votes
2 answers

Pass variable up from page to svelte layout via slot

So I can't figure a way to pass a variable up in my __layout variable from the component displayed in the . I tried a few things, using bind: or let: on the slot but it doesn't work. I get 'myvar' is not a valid binding or cannot have…
vinalti
  • 966
  • 5
  • 26
9
votes
1 answer

Logging both in SSR and client side in SvelteKit routes and components

What kind of a logging solution could be a good fit in SvelteKit if server-side rendering must be enabled? Configurable logging levels Logs to a file/stdout when server-side rendering is run with Node.js adapter Logs to a console if any logging…
Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
9
votes
5 answers

SvelteKit could not resolve dependency even though it's external

I'm making a user authentication page and in that matter, I'm using bcrypt for hashing. Everything was nice and well until I actually use the bcrypt module in the code. Running it in development mode works totally fine and it when previewing the…
Joshua Q
  • 635
  • 5
  • 18
9
votes
1 answer

How to implement cookie authentication | SvelteKit & MongoDB

The question stands as-is - how to implement cookie authentication in a SvelteKit & MongoDB app? Meaning how to properly use hooks, endpoints, establish a DB connection and show it on a boilerplate-ish project.
9
votes
1 answer

In sveltekit , how to pass props in slot using __layout.svelte File?

In __layout file I want to pass one variable lets say btnclicked="HR",and I want to collect same in the component which is rendered in Slot ? how to do it pls help ?
ajay dalwani
  • 99
  • 1
  • 2
9
votes
3 answers

How to serve plain json files with sveltekit?

I tried doing something like this in my endpoint routes/users.json.ts : import * as api from '$lib/api' export async function get({ query, locals }) { const response = await this.fetch('static/data/customers.json') return { status: 200, …
nkostic
  • 565
  • 2
  • 7
  • 19
8
votes
2 answers

Sveltekit package with Tailwind styles

I'm trying to create a package of Svelte components using the svelte packaging library (the one you can set up with npm create svelte@latest and choosing svelte library. I then add tailwind following tailwind's guide…