Skip to content

Commit

Permalink
Merge branch 'master' into gh-6356
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Aug 29, 2022
2 parents 707ad87 + af2d6db commit 9d114e8
Show file tree
Hide file tree
Showing 49 changed files with 509 additions and 349 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-trains-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

prevent test suites from getting published
4 changes: 4 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@
"hip-nails-burn",
"hip-nails-taste",
"hip-trainers-sort",
"hip-trains-vanish",
"hip-walls-flash",
"hip-windows-sit",
"honest-beers-sing",
Expand Down Expand Up @@ -778,6 +779,7 @@
"quiet-knives-refuse",
"quiet-mangos-shop",
"quiet-mugs-matter",
"quiet-poems-tease",
"quiet-singers-fly",
"quiet-terms-fail",
"quiet-waves-compete",
Expand Down Expand Up @@ -1058,6 +1060,7 @@
"tender-geckos-agree",
"tender-pans-explode",
"tender-plants-smell",
"tender-spiders-fail",
"thick-chicken-applaud",
"thick-meals-attend",
"thick-oranges-walk",
Expand Down Expand Up @@ -1251,6 +1254,7 @@
"young-horses-kick",
"young-penguins-camp",
"young-pens-exist",
"young-pumpkins-approve",
"young-scissors-collect",
"young-students-chew",
"young-swans-burn",
Expand Down
5 changes: 5 additions & 0 deletions .changeset/quiet-poems-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[fix] remove unnecessary JSON serialization of server data
7 changes: 7 additions & 0 deletions .changeset/tender-spiders-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@sveltejs/adapter-netlify': patch
'@sveltejs/adapter-vercel': patch
'@sveltejs/kit': patch
---

Use devalue to serialize server-only `load` return values
6 changes: 6 additions & 0 deletions .changeset/young-pumpkins-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@sveltejs/kit': patch
'@sveltejs/package': patch
---

[breaking] require Node 16.14
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ Entry points to be aware of are:

- [`packages/create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte) - code that's run when you create a new project with `npm create svelte@latest`
- [`packages/package`](https://github.com/sveltejs/kit/tree/master/packages/package) - for the `svelte-package` command
- [`packages/kit/src/vite/index.js`](https://github.com/sveltejs/kit/blob/master/packages/kit/src/exports/vite/index.js) - for the Vite plugin
- [`packages/kit/src/core/sync/index.js`](https://github.com/sveltejs/kit/blob/master/packages/kit/src/core/sync/sync.js) - for `svelte-kit sync`, which regenerates routing info and type definitions
- [`packages/kit/src/core`](https://github.com/sveltejs/kit/tree/master/packages/kit/src/core) - code that's called at dev/build-time
- [`packages/kit/src/core/sync`](https://github.com/sveltejs/kit/tree/master/packages/kit/src/core/sync) - for `svelte-kit sync`, which regenerates routing info and type definitions
- [`packages/kit/src/runtime`](https://github.com/sveltejs/kit/tree/master/packages/kit/src/runtime) - code that's called at runtime
- [`packages/kit/src/exports/vite`](https://github.com/sveltejs/kit/tree/master/packages/kit/src/exports/vite) - for all the Vite plugin related stuff
- [`packages/adapter-[platform]`](https://github.com/sveltejs/kit/tree/master/packages) - for the various SvelteKit-provided adapters

Most code called at build-time or from the CLI entry point lives in [packages/kit/src/core](https://github.com/sveltejs/kit/tree/master/packages/kit/src/core). Code that runs for rendering and routing lives in [packages/kit/src/runtime](https://github.com/sveltejs/kit/tree/master/packages/kit/src/runtime). Most changes to SvelteKit itself would involve code in these two directories.

## Testing

Run `pnpm test` to run the tests from all subpackages. Browser tests live in subdirectories of `packages/kit/test` such as `packages/kit/test/apps/basics`.
Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/03-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export async function load({ params }) {
}
```

During client-side navigation, SvelteKit will load this data using `fetch`, which means that the returned value must be serializable as JSON.
During client-side navigation, SvelteKit will load this data from the server, which means that the returned value must be serializable using [devalue](https://github.com/rich-harris/devalue).

#### Actions

Expand Down
4 changes: 2 additions & 2 deletions documentation/docs/05-load.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Loading data

A [`+page.svelte`](/docs/routing#page-page-svelte) or [`+layout.svelte`](/docs/routing#layout-layout-svelte) gets its `data` from a `load` function.

If the `load` function is defined in `+page.js` or `+layout.js` it will run both on the server and in the browser. If it's instead defined in `+page.server.js` or `+layout.server.js` it will only run on the server, in which case it can (for example) make database calls and access private [environment variables](/docs/modules#$env-static-private), but can only return data that can be serialized as JSON. In both cases, the return value (if there is one) must be an object.
If the `load` function is defined in `+page.js` or `+layout.js` it will run both on the server and in the browser. If it's instead defined in `+page.server.js` or `+layout.server.js` it will only run on the server, in which case it can (for example) make database calls and access private [environment variables](/docs/modules#$env-static-private), but can only return data that can be serialized with [devalue](https://github.com/rich-harris/devalue). In both cases, the return value (if there is one) must be an object.

```js
/// file: src/routes/+page.js
Expand Down Expand Up @@ -256,7 +256,7 @@ export async function load({ setHeaders }) {

### Output

The returned `data`, if any, must be an object of values. For a server-only `load` function, these values must be JSON-serializable. Top-level promises will be awaited, which makes it easy to return multiple promises without creating a waterfall:
The returned `data`, if any, must be an object of values. For a server-only `load` function, these values must be serializable with [devalue](https://github.com/rich-harris/devalue). Top-level promises will be awaited, which makes it easy to return multiple promises without creating a waterfall:

```js
// @filename: $types.d.ts
Expand Down
8 changes: 3 additions & 5 deletions documentation/docs/80-migrating.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ If you were using plugins for filetypes that are not automatically handled by [V

#### src/client.js

This file has no equivalent in SvelteKit. Any custom logic (beyond `sapper.start(...)`) should be expressed in your `__layout.svelte` file, inside an `onMount` callback.
This file has no equivalent in SvelteKit. Any custom logic (beyond `sapper.start(...)`) should be expressed in your `+layout.svelte` file, inside an `onMount` callback.

#### src/server.js

Expand Down Expand Up @@ -81,7 +81,7 @@ Routes now are made up of the folder name exclusively to remove ambiguity, the f
| routes/about/index.svelte | routes/about/+page.svelte |
| routes/about.svelte | routes/about/+page.svelte |

Your custom error page component should be renamed from `_error.svelte` to `+error.svelte`. Any `_layout.svelte` files should likewise be renamed `+layout.svelte`. The double underscore prefix is reserved for SvelteKit; your own [private modules](/docs/routing#private-modules) are still denoted with a single `_` prefix (configurable via [`routes`](/docs/configuration#routes) config).
Your custom error page component should be renamed from `_error.svelte` to `+error.svelte`. Any `_layout.svelte` files should likewise be renamed `+layout.svelte`. [Any other files are ignored](https://kit.svelte.dev/docs/routing#other-files).

#### Imports

Expand All @@ -97,9 +97,7 @@ As before, pages and layouts can export a function that allows data to be loaded

This function has been renamed from `preload` to [`load`](/docs/load), it now lives in a `+page.js` (or `+layout.js`) next to its `+page.svelte` (or `+layout.svelte`), and its API has changed. Instead of two arguments — `page` and `session` — there is a single `event` argument.

There is no more `this` object, and consequently no `this.fetch`, `this.error` or `this.redirect`. Instead of returning props directly, `load` now returns an object that _contains_ `props`, alongside various other things.

Lastly, if your page has a `load` method, make sure to return something otherwise you will get `Not found`.
There is no more `this` object, and consequently no `this.fetch`, `this.error` or `this.redirect`. Instead, you can get [`fetch`](https://kit.svelte.dev/docs/load#input-methods-fetch) from the input methods, and both [`error`](https://kit.svelte.dev/docs/load#errors) and [`redirect`](https://kit.svelte.dev/docs/load#redirects) are now thrown.

#### Stores

Expand Down
8 changes: 8 additions & 0 deletions packages/adapter-auto/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @sveltejs/adapter-auto

## 1.0.0-next.69

### Patch Changes

- Updated dependencies [[`c530d337`](https://github.com/sveltejs/kit/commit/c530d33793a228fac684c71ed7926e6217101a90)]:
- @sveltejs/adapter-netlify@1.0.0-next.75
- @sveltejs/adapter-vercel@1.0.0-next.71

## 1.0.0-next.68

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-auto/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sveltejs/adapter-auto",
"version": "1.0.0-next.68",
"version": "1.0.0-next.69",
"repository": {
"type": "git",
"url": "https://github.com/sveltejs/kit",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-cloudflare/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ When configuring your project settings, you must use the following settings:
- **Environment variables**
- `NODE_VERSION`: `16`

> **Important:** You need to add a `NODE_VERSION` environment variable to both the "production" and "preview" environments. You can add this during project setup or later in the Pages project settings. SvelteKit requires Node `16.9` or later, so you should use `16` as the `NODE_VERSION` value.
> **Important:** You need to add a `NODE_VERSION` environment variable to both the "production" and "preview" environments. You can add this during project setup or later in the Pages project settings. SvelteKit requires Node `16.14` or later, so you should use `16` as the `NODE_VERSION` value.
## Environment variables

Expand Down
6 changes: 6 additions & 0 deletions packages/adapter-netlify/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @sveltejs/adapter-netlify

## 1.0.0-next.75

### Patch Changes

- Use devalue to serialize server-only `load` return values ([#6318](https://github.com/sveltejs/kit/pull/6318))

## 1.0.0-next.74

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-netlify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ async function generate_lambda_functions({ builder, publish, split, esm }) {
writeFileSync(`.netlify/functions-internal/${name}.js`, fn);

redirects.push(`${pattern} /.netlify/functions/${name} 200`);
redirects.push(`${pattern}/__data.json /.netlify/functions/${name} 200`);
redirects.push(`${pattern}/__data.js /.netlify/functions/${name} 200`);
}
};
});
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-netlify/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sveltejs/adapter-netlify",
"version": "1.0.0-next.74",
"version": "1.0.0-next.75",
"repository": {
"type": "git",
"url": "https://github.com/sveltejs/kit",
Expand Down
6 changes: 6 additions & 0 deletions packages/adapter-vercel/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @sveltejs/adapter-vercel

## 1.0.0-next.71

### Patch Changes

- Use devalue to serialize server-only `load` return values ([#6318](https://github.com/sveltejs/kit/pull/6318))

## 1.0.0-next.70

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-vercel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export default function ({ external = [], edge, split } = {}) {
sliced_pattern = '^/?';
}

const src = `${sliced_pattern}(?:/__data.json)?$`; // TODO adding /__data.json is a temporary workaround — those endpoints should be treated as distinct routes
const src = `${sliced_pattern}(?:/__data.js)?$`; // TODO adding /__data.js is a temporary workaround — those endpoints should be treated as distinct routes

await generate_function(route.id || 'index', src, entry.generateManifest);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-vercel/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sveltejs/adapter-vercel",
"version": "1.0.0-next.70",
"version": "1.0.0-next.71",
"repository": {
"type": "git",
"url": "https://github.com/sveltejs/kit",
Expand Down
16 changes: 16 additions & 0 deletions packages/kit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# @sveltejs/kit

## 1.0.0-next.448

### Patch Changes

- prevent test suites from getting published ([#6386](https://github.com/sveltejs/kit/pull/6386))

* [fix] remove unnecessary JSON serialization of server data ([#6382](https://github.com/sveltejs/kit/pull/6382))

- [breaking] require Node 16.14 ([#6388](https://github.com/sveltejs/kit/pull/6388))

## 1.0.0-next.447

### Patch Changes

- Use devalue to serialize server-only `load` return values ([#6318](https://github.com/sveltejs/kit/pull/6318))

## 1.0.0-next.446

### Patch Changes
Expand Down
12 changes: 5 additions & 7 deletions packages/kit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sveltejs/kit",
"version": "1.0.0-next.446",
"version": "1.0.0-next.448",
"repository": {
"type": "git",
"url": "https://github.com/sveltejs/kit",
Expand All @@ -12,7 +12,7 @@
"dependencies": {
"@sveltejs/vite-plugin-svelte": "^1.0.1",
"cookie": "^0.5.0",
"devalue": "^2.0.1",
"devalue": "^3.1.2",
"kleur": "^4.1.4",
"magic-string": "^0.26.2",
"mime": "^3.0.0",
Expand All @@ -36,7 +36,6 @@
"rollup": "^2.75.7",
"svelte": "^3.48.0",
"svelte-preprocess": "^4.10.6",
"tiny-glob": "^0.2.9",
"typescript": "^4.7.4",
"uvu": "^0.5.3",
"vite": "^3.0.9"
Expand All @@ -51,9 +50,8 @@
"files": [
"src",
"!src/**/*.spec.js",
"!src/packaging/test",
"!src/core/**/fixtures",
"!src/core/sync/create_manifest_data/test",
"!src/core/**/test",
"types",
"svelte-kit.js"
],
Expand All @@ -66,7 +64,7 @@
"prepublishOnly": "npm run build",
"test": "npm run test:unit && npm run test:integration",
"test:integration": "pnpm run -r --workspace-concurrency 1 --filter=\"./test/**\" test",
"test:unit": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\" -i packaging",
"test:unit": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\"",
"types": "node scripts/extract-types.js",
"postinstall": "node svelte-kit.js sync"
},
Expand All @@ -91,6 +89,6 @@
},
"types": "types/index.d.ts",
"engines": {
"node": ">=16.9"
"node": ">=16.14"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
export const SVELTE_KIT_ASSETS = '/_svelte_kit_assets';

export const GENERATED_COMMENT = '// this file is generated — do not edit it\n';

export const DATA_SUFFIX = '/__data.js';
2 changes: 1 addition & 1 deletion packages/kit/src/core/env.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GENERATED_COMMENT } from './constants.js';
import { GENERATED_COMMENT } from '../constants.js';
import { runtime_base } from './utils.js';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/core/sync/write_ambient.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
import { get_env } from '../../exports/vite/utils.js';
import { GENERATED_COMMENT } from '../constants.js';
import { GENERATED_COMMENT } from '../../constants.js';
import { create_types } from '../env.js';
import { write_if_changed } from './utils.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/exports/vite/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { installPolyfills } from '../../../exports/node/polyfills.js';
import { coalesce_to_error } from '../../../utils/error.js';
import { posixify } from '../../../utils/filesystem.js';
import { load_template } from '../../../core/config/index.js';
import { SVELTE_KIT_ASSETS } from '../../../core/constants.js';
import { SVELTE_KIT_ASSETS } from '../../../constants.js';
import * as sync from '../../../core/sync/sync.js';
import { get_mime_lookup, runtime_base, runtime_prefix } from '../../../core/utils.js';
import { get_env, prevent_illegal_vite_imports, resolve_entry } from '../utils.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/exports/vite/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import sirv from 'sirv';
import { pathToFileURL } from 'url';
import { getRequest, setResponse } from '../../../exports/node/index.js';
import { installPolyfills } from '../../../exports/node/polyfills.js';
import { SVELTE_KIT_ASSETS } from '../../../core/constants.js';
import { SVELTE_KIT_ASSETS } from '../../../constants.js';
import { loadEnv } from 'vite';

/** @typedef {import('http').IncomingMessage} Req */
Expand Down
Loading

0 comments on commit 9d114e8

Please sign in to comment.