Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich Harris committed May 10, 2023
2 parents 2820d05 + bc70b4e commit f344267
Show file tree
Hide file tree
Showing 27 changed files with 221 additions and 249 deletions.
5 changes: 5 additions & 0 deletions .changeset/shy-pears-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: only skip hydration with vite overlay if current page is an error
17 changes: 15 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@ cd kit
pnpm install
```

You can now run SvelteKit by linking it into your project with [pnpm `overrides`](https://pnpm.io/package_json#pnpmoverrides) as demonstrated in the [sandbox example](https://github.com/sveltejs/kit-sandbox) or by running one of the test projects as described in [the testing section](#testing) below.
You can now run SvelteKit by linking it into your project with [pnpm `overrides`](https://pnpm.io/package_json#pnpmoverrides):

```jsonc
{
// ...
"pnpm": {
"overrides": {
"@sveltejs/kit": "link:../path/to/svelte-kit/packages/kit",
// additionally/optional the adapter you're using
"@sveltejs/adapter-auto": "link:../path/to/svelte-kit/packages/adapter-auto"
}
}
}
```

## Code structure

Expand Down Expand Up @@ -44,7 +57,7 @@ Run `pnpm test` to run the tests from all subpackages. Browser tests live in sub

You can run the tests for only a single package by first moving to that directory. E.g. `cd packages/kit`.

You must rebuild each time before running the tests if you've made code changes.
For some packages you must rebuild each time before running the tests if you've made code changes. These packages have a `build` command. Packages like `packages/kit` don't require a build step.

To run a single integration test or otherwise control the running of the tests locally see [the Playwright CLI docs](https://playwright.dev/docs/test-cli). Note that you will need to run these commands from the test project directory such as `packages/kit/test/apps/basics`.

Expand Down
6 changes: 4 additions & 2 deletions documentation/docs/20-core-concepts/20-load.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function load({ params }) {

Thanks to the generated `$types` module, we get full type safety.

A `load` function in a `+page.js` file runs both on the server and in the browser. If your `load` function should _always_ run on the server (because it uses private environment variables, for example, or accesses a database) then it would go in a `+page.server.js` instead.
A `load` function in a `+page.js` file runs both on the server and in the browser (unless combined with `export const ssr = false`, in which case it will [only run in the browser](https://kit.svelte.dev/docs/page-options#ssr)). If your `load` function should _always_ run on the server (because it uses private environment variables, for example, or accesses a database) then it would go in a `+page.server.js` instead.

A more realistic version of your blog post's `load` function, that only runs on the server and pulls data from a database, might look like this:

Expand Down Expand Up @@ -578,10 +578,12 @@ export async function load({ fetch, depends }) {
<button on:click={rerunLoadFunction}>Update random number</button>
```

### When do load functions re-run?

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

- It references a property of `params` whose value has changed
- It references a property of `url` (such as `url.pathname` or `url.search`) whose value has changed
- It references a property of `url` (such as `url.pathname` or `url.search`) whose value has changed. Properties in `request.url` are _not_ tracked
- It calls `await parent()` and a parent `load` function re-ran
- It declared a dependency on a specific URL via [`fetch`](#making-fetch-requests) or [`depends`](types#public-types-loadevent), and that URL was marked invalid with [`invalidate(url)`](modules#$app-navigation-invalidate)
- All active `load` functions were forcibly re-run with [`invalidateAll()`](modules#$app-navigation-invalidateall)
Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/20-core-concepts/40-page-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ SvelteKit will discover pages to prerender automatically, by starting at _entry

Most of the time, that's enough. In some situations, links to pages like `/blog/hello-world` might not exist (or might not exist on prerendered pages), in which case we need to tell SvelteKit about their existence.

This can be done with [`config.kit.prerender.entries`](configuration#prerender), or by exporting an `entries` function from a `+page.js` or `+page.server.js` belonging to a dynamic route:
This can be done with [`config.kit.prerender.entries`](configuration#prerender), or by exporting an `entries` function from a `+page.js`, a `+page.server.js` or a `+server.js` belonging to a dynamic route:

```js
/// file: src/routes/blog/[slug]/+page.server.js
Expand Down
4 changes: 2 additions & 2 deletions documentation/docs/30-advanced/20-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ Sentry.init({/*...*/})
export async function handleError({ error, event }) {
const errorId = crypto.randomUUID();
// example integration with https://sentry.io/
Sentry.captureException(error, { event, errorId });
Sentry.captureException(error, { extra: { event, errorId } });

return {
message: 'Whoops!',
Expand Down Expand Up @@ -208,7 +208,7 @@ Sentry.init({/*...*/})
export async function handleError({ error, event }) {
const errorId = crypto.randomUUID();
// example integration with https://sentry.io/
Sentry.captureException(error, { event, errorId });
Sentry.captureException(error, { extra: { event, errorId } });

return {
message: 'Whoops!',
Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/30-advanced/25-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Sentry.init({/*...*/})
/** @type {import('@sveltejs/kit').HandleServerError} */
export function handleError({ error, event }) {
// example integration with https://sentry.io/
Sentry.captureException(error, { event });
Sentry.captureException(error, { extra: { event } });

return {
message: 'Whoops!',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@svitejs/changesets-changelog-github-compact": "^1.1.0",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"eslint": "^8.33.0",
"eslint-plugin-unicorn": "^46.0.0",
"eslint-plugin-unicorn": "^47.0.0",
"playwright": "1.30.0",
"prettier": "^2.8.0",
"rollup": "^3.7.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/adapter-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
"lint": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
"check": "tsc",
"format": "pnpm lint --write",
"test": "uvu test test.js"
"test": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test"
},
"devDependencies": {
"@playwright/test": "1.30.0",
"@sveltejs/kit": "workspace:^",
"@types/node": "^16.18.6",
"sirv": "^2.0.3",
"svelte": "^3.56.0",
"typescript": "^5.0.4",
"uvu": "^0.5.6",
"vite": "^4.3.0"
},
"peerDependencies": {
"@sveltejs/kit": "^1.5.0"
}
}
}
4 changes: 3 additions & 1 deletion packages/adapter-static/test/apps/prerendered/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
"scripts": {
"dev": "vite dev",
"build": "vite build",
"start": "vite start"
"preview": "sirv -p 5173 -s 200.html build",
"test": "playwright test"
},
"devDependencies": {
"@sveltejs/kit": "workspace:^",
"sirv-cli": "^2.0.2",
"svelte": "^3.56.0",
"vite": "^4.3.0"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { config as default } from '../../utils.js';
27 changes: 27 additions & 0 deletions packages/adapter-static/test/apps/prerendered/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as fs from 'node:fs';
import { expect, test } from '@playwright/test';

const cwd = process.cwd();

test('generates HTML files', () => {
expect(fs.existsSync(`${cwd}/build/index.html`)).toBeTruthy();
});

test('prerenders a page', async ({ page }) => {
await page.goto('/');
expect(await page.textContent('h1')).toEqual('This page was prerendered');
expect(await page.textContent('p')).toEqual('answer: 42');
});

test('prerenders an unreferenced endpoint with explicit `prerender` setting', async () => {
expect(fs.existsSync(`${cwd}/build/endpoint/explicit.json`)).toBeTruthy();
});

test('prerenders a referenced endpoint with implicit `prerender` setting', async () => {
expect(fs.existsSync(`${cwd}/build/endpoint/implicit.json`)).toBeTruthy();
});

test('exposes public env vars to the client', async ({ page }) => {
await page.goto('/public-env');
expect(await page.textContent('h1')).toEqual('The answer is 42');
});
3 changes: 2 additions & 1 deletion packages/adapter-static/test/apps/spa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"scripts": {
"dev": "vite dev",
"build": "vite build",
"start": "sirv -s 200.html build"
"preview": "sirv -p 5173 -s 200.html build",
"test": "playwright test"
},
"devDependencies": {
"@sveltejs/adapter-node": "workspace:^",
Expand Down
1 change: 1 addition & 0 deletions packages/adapter-static/test/apps/spa/playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { config as default } from '../../utils.js';
29 changes: 29 additions & 0 deletions packages/adapter-static/test/apps/spa/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as fs from 'node:fs';
import { expect, test } from '@playwright/test';

const cwd = process.cwd();

test('generates a fallback page', async ({ page }) => {
expect(fs.existsSync(`${cwd}/build/200.html`)).toBeTruthy();

await page.goto('/fallback/a/b/c');
expect(await page.textContent('h1')).toEqual('the fallback page was rendered');
});

test('does not prerender pages without prerender=true', () => {
expect(fs.existsSync(`${cwd}/build/index.html`)).toBeFalsy();
});

test('prerenders page with prerender=true', () => {
expect(fs.existsSync(`${cwd}/build/about.html`)).toBeTruthy();
});

test('renders content in fallback page when JS runs', async ({ page }) => {
await page.goto('/');
expect(await page.textContent('h1')).toEqual('This page was not prerendered');
});

test('renders error page for missing page', async ({ page }) => {
await page.goto('/nosuchpage');
expect(await page.textContent('h1')).toEqual('404');
});
55 changes: 0 additions & 55 deletions packages/adapter-static/test/test.js

This file was deleted.

Loading

0 comments on commit f344267

Please sign in to comment.