Skip to content

Commit 61396cd

Browse files
committed
merge master
2 parents 7317fd7 + 06cf3cd commit 61396cd

38 files changed

+195
-88
lines changed

.changeset/famous-points-complain.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/package': minor
3+
---
4+
5+
feat: use Svelte 4 typings when packaging if dependencies allow it

.changeset/shy-colts-sniff.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
feat: more helpful error for preview if build output doesn't exist

.changeset/two-terms-remain.md

-5
This file was deleted.

documentation/docs/20-core-concepts/10-routing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ Data returned from a layout's `load` function is also available to all its child
238238
</script>
239239
```
240240

241-
> Often, layout data is unchanged when navigating between pages. SvelteKit will intelligently re-run [`load`](load) functions when necessary.
241+
> Often, layout data is unchanged when navigating between pages. SvelteKit will intelligently rerun [`load`](load) functions when necessary.
242242
243243
### +layout.server.js
244244

documentation/docs/20-core-concepts/20-load.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -479,15 +479,15 @@ This is useful for creating skeleton loading states, for example:
479479

480480
On platforms that do not support streaming, such as AWS Lambda, responses will be buffered. This means the page will only render once all promises resolve.
481481

482-
> Streaming data will only work when JavaScript is enabled. You should avoid returning nested promises from a universal `load` function if the page is server rendered, as these are _not_ streamed — instead, the promise is recreated when the function re-runs in the browser.
482+
> Streaming data will only work when JavaScript is enabled. You should avoid returning nested promises from a universal `load` function if the page is server rendered, as these are _not_ streamed — instead, the promise is recreated when the function reruns in the browser.
483483
484484
## Parallel loading
485485

486486
When rendering (or navigating to) a page, SvelteKit runs all `load` functions concurrently, avoiding a waterfall of requests. During client-side navigation, the result of calling multiple server `load` functions are grouped into a single response. Once all `load` functions have returned, the page is rendered.
487487

488488
## Rerunning load functions
489489

490-
SvelteKit tracks the dependencies of each `load` function to avoid re-running it unnecessarily during navigation.
490+
SvelteKit tracks the dependencies of each `load` function to avoid rerunning it unnecessarily during navigation.
491491

492492
For example, given a pair of `load` functions like these...
493493

@@ -529,15 +529,15 @@ export async function load() {
529529
}
530530
```
531531

532-
...the one in `+page.server.js` will re-run if we navigate from `/blog/trying-the-raw-meat-diet` to `/blog/i-regret-my-choices` because `params.slug` has changed. The one in `+layout.server.js` will not, because the data is still valid. In other words, we won't call `db.getPostSummaries()` a second time.
532+
...the one in `+page.server.js` will rerun if we navigate from `/blog/trying-the-raw-meat-diet` to `/blog/i-regret-my-choices` because `params.slug` has changed. The one in `+layout.server.js` will not, because the data is still valid. In other words, we won't call `db.getPostSummaries()` a second time.
533533

534-
A `load` function that calls `await parent()` will also re-run if a parent `load` function is re-run.
534+
A `load` function that calls `await parent()` will also rerun if a parent `load` function is rerun.
535535

536-
Dependency tracking does not apply _after_ the `load` function has returned — for example, accessing `params.x` inside a nested [promise](#streaming-with-promises) will not cause the function to re-run when `params.x` changes. (Don't worry, you'll get a warning in development if you accidentally do this.) Instead, access the parameter in the main body of your `load` function.
536+
Dependency tracking does not apply _after_ the `load` function has returned — for example, accessing `params.x` inside a nested [promise](#streaming-with-promises) will not cause the function to rerun when `params.x` changes. (Don't worry, you'll get a warning in development if you accidentally do this.) Instead, access the parameter in the main body of your `load` function.
537537

538538
### Manual invalidation
539539

540-
You can also re-run `load` functions that apply to the current page using [`invalidate(url)`](modules#$app-navigation-invalidate), which re-runs all `load` functions that depend on `url`, and [`invalidateAll()`](modules#$app-navigation-invalidateall), which re-runs every `load` function. Server load functions will never automatically depend on a fetched `url` to avoid leaking secrets to the client.
540+
You can also rerun `load` functions that apply to the current page using [`invalidate(url)`](modules#$app-navigation-invalidate), which reruns all `load` functions that depend on `url`, and [`invalidateAll()`](modules#$app-navigation-invalidateall), which reruns every `load` function. Server load functions will never automatically depend on a fetched `url` to avoid leaking secrets to the client.
541541

542542
A `load` function depends on `url` if it calls `fetch(url)` or `depends(url)`. Note that `url` can be a custom identifier that starts with `[a-z]:`:
543543

@@ -566,7 +566,7 @@ export async function load({ fetch, depends }) {
566566
export let data;
567567
568568
function rerunLoadFunction() {
569-
// any of these will cause the `load` function to re-run
569+
// any of these will cause the `load` function to rerun
570570
invalidate('app:random');
571571
invalidate('https://api.example.com/random-number');
572572
invalidate(url => url.href.includes('random-number'));
@@ -578,19 +578,19 @@ export async function load({ fetch, depends }) {
578578
<button on:click={rerunLoadFunction}>Update random number</button>
579579
```
580580

581-
### When do load functions re-run?
581+
### When do load functions rerun?
582582

583-
To summarize, a `load` function will re-run in the following situations:
583+
To summarize, a `load` function will rerun in the following situations:
584584

585585
- It references a property of `params` whose value has changed
586586
- It references a property of `url` (such as `url.pathname` or `url.search`) whose value has changed. Properties in `request.url` are _not_ tracked
587-
- It calls `await parent()` and a parent `load` function re-ran
587+
- It calls `await parent()` and a parent `load` function reran
588588
- It declared a dependency on a specific URL via [`fetch`](#making-fetch-requests) (universal load only) or [`depends`](types#public-types-loadevent), and that URL was marked invalid with [`invalidate(url)`](modules#$app-navigation-invalidate)
589-
- All active `load` functions were forcibly re-run with [`invalidateAll()`](modules#$app-navigation-invalidateall)
589+
- All active `load` functions were forcibly rerun with [`invalidateAll()`](modules#$app-navigation-invalidateall)
590590

591591
`params` and `url` can change in response to a `<a href="..">` link click, a [`<form>` interaction](form-actions#get-vs-post), a [`goto`](modules#$app-navigation-goto) invocation, or a [`redirect`](modules#sveltejs-kit-redirect).
592592

593-
Note that re-running a `load` function will update the `data` prop inside the corresponding `+layout.svelte` or `+page.svelte`; it does _not_ cause the component to be recreated. As a result, internal state is preserved. If this isn't what you want, you can reset whatever you need to reset inside an [`afterNavigate`](modules#$app-navigation-afternavigate) callback, and/or wrap your component in a [`{#key ...}`](https://svelte.dev/docs#template-syntax-key) block.
593+
Note that rerunning a `load` function will update the `data` prop inside the corresponding `+layout.svelte` or `+page.svelte`; it does _not_ cause the component to be recreated. As a result, internal state is preserved. If this isn't what you want, you can reset whatever you need to reset inside an [`afterNavigate`](modules#$app-navigation-afternavigate) callback, and/or wrap your component in a [`{#key ...}`](https://svelte.dev/docs#template-syntax-key) block.
594594

595595
## Further reading
596596

documentation/docs/20-core-concepts/30-form-actions.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export const actions = {
249249

250250
After an action runs, the page will be re-rendered (unless a redirect or an unexpected error occurs), with the action's return value available to the page as the `form` prop. This means that your page's `load` functions will run after the action completes.
251251

252-
Note that `handle` runs before the action is invoked, and does not re-run before the `load` functions. This means that if, for example, you use `handle` to populate `event.locals` based on a cookie, you must update `event.locals` when you set or delete the cookie in an action:
252+
Note that `handle` runs before the action is invoked, and does not rerun before the `load` functions. This means that if, for example, you use `handle` to populate `event.locals` based on a cookie, you must update `event.locals` when you set or delete the cookie in an action:
253253

254254
```js
255255
/// file: src/hooks.server.js
@@ -424,7 +424,7 @@ We can also implement progressive enhancement ourselves, without `use:enhance`,
424424
const result = deserialize(await response.text());
425425
426426
if (result.type === 'success') {
427-
// re-run all `load` functions, following the successful update
427+
// rerun all `load` functions, following the successful update
428428
await invalidateAll();
429429
}
430430

documentation/docs/20-core-concepts/50-state-management.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ When you navigate around your application, SvelteKit reuses existing layout and
140140
<div>{@html data.content}</div>
141141
```
142142

143-
...then navigating from `/blog/my-short-post` to `/blog/my-long-post` won't cause the component to be destroyed and recreated. The `data` prop (and by extension `data.title` and `data.content`) will change, but because the code isn't re-running, `estimatedReadingTime` won't be recalculated.
143+
...then navigating from `/blog/my-short-post` to `/blog/my-long-post` won't cause the component to be destroyed and recreated. The `data` prop (and by extension `data.title` and `data.content`) will change, but because the code isn't rerunning, `estimatedReadingTime` won't be recalculated.
144144

145145
Instead, we need to make the value [_reactive_](https://learn.svelte.dev/tutorial/reactive-assignments):
146146

packages/kit/CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @sveltejs/kit
22

3+
## 1.22.1
4+
5+
### Patch Changes
6+
7+
- perf: only have Vite generate relative paths when required ([#10287](https://github.com/sveltejs/kit/pull/10287))
8+
39
## 1.22.0
410

511
### Minor Changes
@@ -4360,7 +4366,7 @@ Starting from now all releases follow semver and changes will be listed as Major
43604366

43614367
### Patch Changes
43624368

4363-
- d279e36: Add invalidate(url) API for re-running load functions ([#1303](https://github.com/sveltejs/kit/pull/1303))
4369+
- d279e36: Add invalidate(url) API for rerunning load functions ([#1303](https://github.com/sveltejs/kit/pull/1303))
43644370

43654371
## 1.0.0-next.97
43664372

packages/kit/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sveltejs/kit",
3-
"version": "1.22.0",
3+
"version": "1.22.1",
44
"description": "The fastest way to build Svelte apps",
55
"repository": {
66
"type": "git",

packages/kit/src/exports/vite/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,14 @@ function kit({ svelte_config }) {
541541
// see the kit.output.preloadStrategy option for details on why we have multiple options here
542542
const ext = kit.output.preloadStrategy === 'preload-mjs' ? 'mjs' : 'js';
543543

544+
// We could always use a relative asset base path here, but it's better for performance not to.
545+
// E.g. Vite generates `new URL('/asset.png', import.meta).href` for a relative path vs just '/asset.png'.
546+
// That's larger and takes longer to run and also causes an HTML diff between SSR and client
547+
// causing us to do a more expensive hydration check.
548+
const client_base = kit.paths.relative || kit.paths.assets ? './' : kit.paths.base || '/';
549+
544550
new_config = {
545-
base: ssr ? assets_base(kit) : './',
551+
base: ssr ? assets_base(kit) : client_base,
546552
build: {
547553
copyPublicDir: !ssr,
548554
cssCodeSplit: true,

packages/kit/src/exports/vite/preview/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ export async function preview(vite, vite_config, svelte_config) {
3636

3737
const dir = join(svelte_config.kit.outDir, 'output/server');
3838

39+
if (!fs.existsSync(dir)) {
40+
throw new Error(`Server files not found at ${dir}, did you run \`build\` first?`);
41+
}
42+
3943
/** @type {import('types').ServerInternalModule} */
4044
const { set_assets } = await import(pathToFileURL(join(dir, 'internal.js')).href);
4145

packages/kit/src/version.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// generated during release, do not modify
22

33
/** @type {string} */
4-
export const VERSION = '1.22.0';
4+
export const VERSION = '1.22.1';

packages/migrate/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# svelte-migrate
22

3+
## 1.2.5
4+
5+
### Patch Changes
6+
7+
- fix: note old eslint plugin deprecation ([#10319](https://github.com/sveltejs/kit/pull/10319))
8+
39
## 1.2.4
410

511
### Patch Changes

packages/migrate/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "svelte-migrate",
3-
"version": "1.2.4",
3+
"version": "1.2.5",
44
"description": "A CLI for migrating Svelte(Kit) codebases",
55
"repository": {
66
"type": "git",

packages/package/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
"chokidar": "^3.5.3",
1515
"kleur": "^4.1.5",
1616
"sade": "^1.8.1",
17-
"svelte2tsx": "~0.6.16"
17+
"semver": "^7.5.3",
18+
"svelte2tsx": "~0.6.19"
1819
},
1920
"devDependencies": {
2021
"@types/node": "^16.18.6",
22+
"@types/semver": "^7.5.0",
2123
"svelte": "^4.0.5",
2224
"svelte-preprocess": "^5.0.4",
2325
"typescript": "^4.9.4",

packages/package/src/config.js

+14
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,17 @@ export async function load_config({ cwd = process.cwd() } = {}) {
2525

2626
return config;
2727
}
28+
29+
/**
30+
* @param {string} cwd
31+
* @returns Record<string, any>
32+
*/
33+
export function load_pkg_json(cwd = process.cwd()) {
34+
const pkg_json_file = path.join(cwd, 'package.json');
35+
36+
if (!fs.existsSync(pkg_json_file)) {
37+
return {};
38+
}
39+
40+
return JSON.parse(fs.readFileSync(pkg_json_file, 'utf-8'));
41+
}

packages/package/src/typescript.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import * as fs from 'node:fs';
22
import * as path from 'node:path';
33
import { createRequire } from 'node:module';
4+
import semver from 'semver';
45
import { posixify, mkdirp, rimraf, walk } from './filesystem.js';
56
import { resolve_aliases, write } from './utils.js';
67
import { emitDts } from 'svelte2tsx';
8+
import { load_pkg_json } from './config.js';
79

810
/**
911
* Generates d.ts files by invoking TypeScript's "emit d.ts files from input files".
@@ -22,9 +24,14 @@ export async function emit_dts(input, output, cwd, alias, files) {
2224
mkdirp(tmp);
2325

2426
const require = createRequire(import.meta.url);
27+
const pkg = load_pkg_json(cwd);
28+
const svelte_dep = pkg.peerDependencies?.svelte || pkg.dependencies?.svelte || '3.0';
29+
const no_svelte_3 = !semver.intersects(svelte_dep, '^3.0.0');
2530
await emitDts({
2631
libRoot: input,
27-
svelteShimsPath: require.resolve('svelte2tsx/svelte-shims.d.ts'),
32+
svelteShimsPath: no_svelte_3
33+
? require.resolve('svelte2tsx/svelte-shims-v4.d.ts')
34+
: require.resolve('svelte2tsx/svelte-shims.d.ts'),
2835
declarationDir: path.relative(cwd, tmp)
2936
});
3037

packages/package/test/fixtures/javascript/expected/Test.svelte.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @typedef {typeof __propDef.props} TestProps */
22
/** @typedef {typeof __propDef.events} TestEvents */
33
/** @typedef {typeof __propDef.slots} TestSlots */
4-
export default class Test extends SvelteComponentTyped<
4+
export default class Test extends SvelteComponent<
55
{
66
astring?: string;
77
},
@@ -21,7 +21,7 @@ export default class Test extends SvelteComponentTyped<
2121
export type TestProps = typeof __propDef.props;
2222
export type TestEvents = typeof __propDef.events;
2323
export type TestSlots = typeof __propDef.slots;
24-
import { SvelteComponentTyped } from 'svelte';
24+
import { SvelteComponent } from 'svelte';
2525
declare const __propDef: {
2626
props: {
2727
astring?: string;

packages/package/test/fixtures/javascript/expected/Test2.svelte.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @typedef {typeof __propDef.props} Test2Props */
22
/** @typedef {typeof __propDef.events} Test2Events */
33
/** @typedef {typeof __propDef.slots} Test2Slots */
4-
export default class Test2 extends SvelteComponentTyped<
4+
export default class Test2 extends SvelteComponent<
55
{
66
foo: boolean;
77
},
@@ -13,7 +13,7 @@ export default class Test2 extends SvelteComponentTyped<
1313
export type Test2Props = typeof __propDef.props;
1414
export type Test2Events = typeof __propDef.events;
1515
export type Test2Slots = typeof __propDef.slots;
16-
import { SvelteComponentTyped } from 'svelte';
16+
import { SvelteComponent } from 'svelte';
1717
declare const __propDef: {
1818
props: {
1919
foo: import('./foo').Foo;

packages/package/test/fixtures/javascript/expected/internal/Test.svelte.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @typedef {typeof __propDef.props} TestProps */
22
/** @typedef {typeof __propDef.events} TestEvents */
33
/** @typedef {typeof __propDef.slots} TestSlots */
4-
export default class Test extends SvelteComponentTyped<
4+
export default class Test extends SvelteComponent<
55
{
66
foo: boolean;
77
},
@@ -13,7 +13,7 @@ export default class Test extends SvelteComponentTyped<
1313
export type TestProps = typeof __propDef.props;
1414
export type TestEvents = typeof __propDef.events;
1515
export type TestSlots = typeof __propDef.slots;
16-
import { SvelteComponentTyped } from 'svelte';
16+
import { SvelteComponent } from 'svelte';
1717
declare const __propDef: {
1818
props: {
1919
foo: import('./foo').Foo;

packages/package/test/fixtures/resolve-alias/expected/Test.svelte.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SvelteComponentTyped } from 'svelte';
1+
import { SvelteComponent } from 'svelte';
22
declare const __propDef: {
33
props: {
44
bar?: import('./sub/foo').Foo;
@@ -11,5 +11,5 @@ declare const __propDef: {
1111
export type TestProps = typeof __propDef.props;
1212
export type TestEvents = typeof __propDef.events;
1313
export type TestSlots = typeof __propDef.slots;
14-
export default class Test extends SvelteComponentTyped<TestProps, TestEvents, TestSlots> {}
14+
export default class Test extends SvelteComponent<TestProps, TestEvents, TestSlots> {}
1515
export {};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
import { createEventDispatcher } from 'svelte';
3+
export const astring = 'potato';
4+
const dispatch = createEventDispatcher();
5+
dispatch('event', true);
6+
</script>
7+
8+
<slot {astring} />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { SvelteComponentTyped } from 'svelte';
2+
declare const __propDef: {
3+
props: {
4+
astring?: string;
5+
};
6+
events: {
7+
event: CustomEvent<boolean>;
8+
} & {
9+
[evt: string]: CustomEvent<any>;
10+
};
11+
slots: {
12+
default: {
13+
astring: string;
14+
};
15+
};
16+
};
17+
export type TestProps = typeof __propDef.props;
18+
export type TestEvents = typeof __propDef.events;
19+
export type TestSlots = typeof __propDef.slots;
20+
export default class Test extends SvelteComponentTyped<TestProps, TestEvents, TestSlots> {
21+
get astring(): string;
22+
}
23+
export {};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as Test } from './Test.svelte';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as Test } from './Test.svelte';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "svelte-3-types",
3+
"private": true,
4+
"version": "1.0.0",
5+
"description": "creates Svelte 3 backwards compatible types",
6+
"type": "module",
7+
"peerDependencies": {
8+
"svelte": "^3.0.0 || ^4.0.0"
9+
},
10+
"exports": {
11+
".": {
12+
"types": "./dist/index.d.ts",
13+
"svelte": "./dist/index.js"
14+
}
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script lang="ts">
2+
import { createEventDispatcher } from 'svelte';
3+
export const astring: string = 'potato';
4+
5+
const dispatch = createEventDispatcher<{ event: boolean }>();
6+
dispatch('event', true);
7+
</script>
8+
9+
<slot {astring} />

0 commit comments

Comments
 (0)