-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # .vscode/launch.json # package.json # pnpm-lock.yaml
- Loading branch information
Showing
12 changed files
with
707 additions
and
315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Svelte 5 and SvelteKit 2 | ||
|
||
## Peculiarities | ||
|
||
Peculiarities encountered in Svelte 5 and SvelteKit 2. | ||
|
||
### `./$types` | ||
|
||
Works: | ||
|
||
```ts | ||
import type { PageServerLoad } from './$types'; | ||
``` | ||
|
||
Doesn't work: | ||
|
||
```ts | ||
import { type PageServerLoad } from './$types'; | ||
``` | ||
|
||
### Lifecycle and Context | ||
|
||
`setContext()`, `getContext()` and `hasContext()` don't work and throw errors in modules if not called from `onMount()` or called on the server side. | ||
|
||
As an extension, `useState()` does not work in the same situations. | ||
|
||
### Runes type definitions | ||
|
||
`$props` cannot take type parameter, should use type on the left-hand side. `$state` type on left-hand side does not work well, should use type parameter. | ||
|
||
Works: | ||
|
||
```ts | ||
let { value }: { value: ValueType } = $props(); | ||
let value = $state<ValueType>(initialValue); | ||
``` | ||
|
||
Does not work: | ||
|
||
```ts | ||
let { value } = $props<{ value: ValueType }>(); | ||
let value: ValueType = $state(initialValue); | ||
``` | ||
|
||
## ChatGPT Prompts | ||
|
||
### Generate Svelte 5 / SvelteKit 2 code | ||
|
||
System prompt: | ||
|
||
```text | ||
Use Svelte 5 runes. They are not imported but compiled, `let value = $state<valueType>(initialValue);` and `value` can be read or set directly, it will be reactive. For component props, use `let { prop1, prop2, ...args } : { prop1: prop1Type, prop2: prop2Type, ... } = $props();` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.