Skip to content

Commit

Permalink
Merge branch 'master' into playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Feb 23, 2022
2 parents e39a1eb + 385b1a5 commit 9e3c8ab
Show file tree
Hide file tree
Showing 35 changed files with 177 additions and 103 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-onions-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

create `__data.json` for pathnames with trailing slashes, including `/`
5 changes: 5 additions & 0 deletions .changeset/eight-chicken-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Disable meta http-equiv tags for static amp configuration
5 changes: 5 additions & 0 deletions .changeset/four-ties-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-auto': patch
---

Attempt to bump @next version of adapter-auto
5 changes: 5 additions & 0 deletions .changeset/great-seahorses-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-svelte': patch
---

fix `@typescript-eslint/no-empty-interface` lint error when starting a new app with eslint
12 changes: 9 additions & 3 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"@sveltejs/app-utils": "0.0.18",
"create-svelte": "2.0.0-alpha.19",
"@sveltejs/kit": "0.0.30",
"@sveltejs/vite-plugin-svelte": "1.0.0-next.0",
"@sveltejs/vite-plugin-svelte": "0.0.1",
"@sveltejs/adapter-cloudflare-workers": "0.0.1",
"@sveltejs/adapter-cloudflare": "1.0.0-next.0",
"@sveltejs/adapter-auto": "1.0.0-next",
"@sveltejs/adapter-cloudflare": "0.0.1",
"@sveltejs/adapter-auto": "0.0.1",
"set-env-action": "1.0.0",
"~TODO~": "0.0.1",
"prerendering-test-basics": "0.0.1",
Expand Down Expand Up @@ -51,6 +51,7 @@
"brave-turkeys-bathe",
"brave-weeks-allow",
"breezy-games-count",
"breezy-onions-remember",
"breezy-sheep-dress",
"breezy-students-refuse",
"bright-cherries-hug",
Expand Down Expand Up @@ -141,6 +142,7 @@
"early-snakes-peel",
"early-wasps-obey",
"eight-birds-run",
"eight-chicken-sin",
"eight-glasses-sparkle",
"eight-hats-worry",
"eight-keys-give",
Expand Down Expand Up @@ -197,6 +199,7 @@
"four-cheetahs-yawn",
"four-news-turn",
"four-pillows-give",
"four-ties-destroy",
"fresh-adults-ring",
"fresh-dolls-destroy",
"fresh-hats-tie",
Expand Down Expand Up @@ -240,6 +243,7 @@
"great-guests-visit",
"great-kangaroos-eat",
"great-queens-rule",
"great-seahorses-fry",
"green-mayflies-shave",
"green-spoons-count",
"grumpy-days-compete",
Expand Down Expand Up @@ -687,6 +691,7 @@
"tidy-pigs-peel",
"tidy-turkeys-rule",
"tidy-wasps-shave",
"tiny-badgers-love",
"tiny-candles-repeat",
"tiny-files-smile",
"tiny-gorillas-whisper",
Expand Down Expand Up @@ -714,6 +719,7 @@
"twelve-feet-deny",
"twelve-goats-knock",
"twelve-onions-burn",
"twenty-dogs-shout",
"twenty-dryers-hope",
"twenty-hairs-shave",
"twenty-numbers-destroy",
Expand Down
5 changes: 5 additions & 0 deletions .changeset/tiny-badgers-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Ignore click event if url does not have origin (e.g. `mailto:`, `tel:`)
6 changes: 6 additions & 0 deletions .changeset/twenty-dogs-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@sveltejs/adapter-auto': patch
'@sveltejs/adapter-cloudflare': patch
---

Attempt to force @next version bump
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: pnpm/action-setup@v2.1.0
- uses: pnpm/action-setup@v2.2.0
with:
version: 6.23.2
- uses: actions/setup-node@v2
Expand All @@ -39,7 +39,7 @@ jobs:
steps:
- run: git config --global core.autocrlf false
- uses: actions/checkout@v2
- uses: pnpm/action-setup@v2.1.0
- uses: pnpm/action-setup@v2.2.0
with:
version: 6.23.2
- uses: actions/setup-node@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0
- uses: pnpm/action-setup@v2.1.0
- uses: pnpm/action-setup@v2.2.0
with:
version: 6.23.2
- name: Setup Node.js
Expand Down
46 changes: 24 additions & 22 deletions documentation/docs/01-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ A file or directory can have multiple dynamic parts, like `[id]-[category].svelt

### Endpoints

Endpoints are modules written in `.js` (or `.ts`) files that export functions corresponding to HTTP methods. Their job is to allow pages to read and write data that is only available on the server (for example in a database, or on the filesystem).

If an endpoint has the same filename as a page (except for the extension), the page will get its props from the endpoint. So a page like `src/routes/items/[id].svelte` could get its props from this file:
Endpoints are modules written in `.js` (or `.ts`) files that export [request handler](/docs/types#sveltejs-kit-requesthandler) functions corresponding to HTTP methods. Their job is to make it possible to read and write data that is only available on the server (for example in a database, or on the filesystem).

```js
/// file: src/routes/items/[id].js
Expand Down Expand Up @@ -81,7 +79,7 @@ export async function get({ params }) {

> All server-side code, including endpoints, has access to `fetch` in case you need to request data from external APIs. Don't worry about the `$lib` import, we'll get to that [later](/docs/modules#$lib).
The job of this function is to return a `{ status, headers, body }` object representing the response, where `status` is an [HTTP status code](https://httpstatusdogs.com):
The job of a [request handler](/docs/types#sveltejs-kit-requesthandler) is to return a `{ status, headers, body }` object representing the response, where `status` is an [HTTP status code](https://httpstatusdogs.com):

- `2xx` — successful response (default is `200`)
- `3xx` — redirection (should be accompanied by a `location` header)
Expand All @@ -90,7 +88,11 @@ The job of this function is to return a `{ status, headers, body }` object repre

> If `{fallthrough: true}` is returned SvelteKit will [fall through](/docs/routing#advanced-routing-fallthrough-routes) to other routes until something responds, or will respond with a generic 404.
The returned `body` corresponds to the page's props:
#### Page endpoints

If an endpoint has the same filename as a page (except for the extension), the page gets its props from the endpoint — via `fetch` during client-side navigation, or via direct function call during SSR.

A page like `src/routes/items/[id].svelte` could get its props from the `body` in the endpoint above:

```svelte
/// file: src/routes/items/[id].svelte
Expand All @@ -102,6 +104,23 @@ The returned `body` corresponds to the page's props:
<h1>{item.title}</h1>
```

Because the page and route have the same URL, you will need to include an `accept: application/json` header to get JSON from the endpoint rather than HTML from the page. You can also get the raw data by appending `/__data.json` to the URL, e.g. `/items/__data.json`.

#### Standalone endpoints

Most commonly, endpoints exist to provide data to the page with which they're paired. They can, however, exist separately from pages. Standalone endpoints have slightly more flexibility over the returned `body` type — in addition to objects, they can return a `Uint8Array`.

Standalone endpoints can be given a file extension if desired, or accessed directly if not:

| filename | endpoint |
| ----------------------------- | ---------- |
| src/routes/data/index.json.js | /data.json |
| src/routes/data.json.js | /data.json |
| src/routes/data/index.js | /data |
| src/routes/data.js | /data |

> Support for streaming request and response bodies is [coming soon](https://github.com/sveltejs/kit/issues/3419).
#### POST, PUT, PATCH, DELETE

Endpoints can handle any HTTP method — not just `GET` — by exporting the corresponding function:
Expand Down Expand Up @@ -191,8 +210,6 @@ export async function post({ request }) {
</form>
```

If you request the route with an `accept: application/json` header, SvelteKit will render the endpoint data as JSON, rather than the page as HTML. You can also get the raw data by appending `/__data.json` to the URL, e.g. `/items/__data.json`.

#### Body parsing

The `request` object is an instance of the standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) class. As such, accessing the request body is easy:
Expand Down Expand Up @@ -263,21 +280,6 @@ export default config;

> Using native `<form>` behaviour ensures your app continues to work when JavaScript fails or is disabled.
### Standalone endpoints

Most commonly, endpoints exist to provide data to the page with which they're paired. They can, however, exist separately from pages. Standalone endpoints have slightly more flexibility over the returned `body` type — in addition to objects, they can return a string or a `Uint8Array`.

> Support for streaming request and response bodies is [coming soon](https://github.com/sveltejs/kit/issues/3419).
Standalone endpoints can be given a file extension if desired, or accessed directly if not:

| filename | endpoint |
| ----------------------------- | ---------- |
| src/routes/data/index.json.js | /data.json |
| src/routes/data.json.js | /data.json |
| src/routes/data/index.js | /data |
| src/routes/data.js | /data |

### Private modules

Files and directories with a leading `_` or `.` (other than [`.well-known`](https://en.wikipedia.org/wiki/Well-known_URI)) are private by default, meaning that they do not create routes (but can be imported by files that do). You can configure which modules are considered public or private with the [`routes`](/docs/configuration#routes) configuration.
Expand Down
15 changes: 15 additions & 0 deletions packages/adapter-auto/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# @sveltejs/adapter-auto

## 1.0.0-next.26

### Patch Changes

- Attempt to force @next version bump ([#4088](https://github.com/sveltejs/kit/pull/4088))

- Updated dependencies [[`46f44a61`](https://github.com/sveltejs/kit/commit/46f44a61624bed525e393e669da9b7db566a1e18)]:
- @sveltejs/adapter-cloudflare@1.0.0-next.13

## 1.0.0-next.25

### Patch Changes

- Attempt to bump @next version of adapter-auto ([#4082](https://github.com/sveltejs/kit/pull/4082))

## 1.0.0-next.24

### 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.24",
"version": "1.0.0-next.26",
"repository": {
"type": "git",
"url": "https://github.com/sveltejs/kit",
Expand Down
6 changes: 6 additions & 0 deletions packages/adapter-cloudflare/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @sveltejs/adapter-cloudflare

## 1.0.0-next.13

### Patch Changes

- Attempt to force @next version bump ([#4088](https://github.com/sveltejs/kit/pull/4088))

## 1.0.0-next.12

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-cloudflare/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sveltejs/adapter-cloudflare",
"version": "1.0.0-next.12",
"version": "1.0.0-next.13",
"repository": {
"type": "git",
"url": "https://github.com/sveltejs/kit",
Expand Down
1 change: 0 additions & 1 deletion packages/adapter-netlify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ During compilation, redirect rules are automatically appended to your `_redirect

[functions]
directory = "functions"
node_bundler = "esbuild"
```

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

## 2.0.0-next.120

### Patch Changes

- fix `@typescript-eslint/no-empty-interface` lint error when starting a new app with eslint ([#4077](https://github.com/sveltejs/kit/pull/4077))

## 2.0.0-next.119

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/create-svelte/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-svelte",
"version": "2.0.0-next.119",
"version": "2.0.0-next.120",
"repository": {
"type": "git",
"url": "https://github.com/sveltejs/kit",
Expand Down
6 changes: 3 additions & 3 deletions packages/create-svelte/templates/default/src/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ declare namespace App {
userid: string;
}

interface Platform {}
// interface Platform {}

interface Session {}
// interface Session {}

interface Stuff {}
// interface Stuff {}
}
11 changes: 4 additions & 7 deletions packages/create-svelte/templates/skeleton/src/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
// See https://kit.svelte.dev/docs/types#the-app-namespace
// for information about these interfaces
declare namespace App {
interface Locals {}

interface Platform {}

interface Session {}

interface Stuff {}
// interface Locals {}
// interface Platform {}
// interface Session {}
// interface Stuff {}
}
14 changes: 14 additions & 0 deletions packages/kit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# @sveltejs/kit

## 1.0.0-next.284

### Patch Changes

- Disable meta http-equiv tags for static amp configuration ([#4073](https://github.com/sveltejs/kit/pull/4073))

* Ignore click event if url does not have origin (e.g. `mailto:`, `tel:`) ([#4072](https://github.com/sveltejs/kit/pull/4072))

## 1.0.0-next.283

### Patch Changes

- create `__data.json` for pathnames with trailing slashes, including `/` ([#4066](https://github.com/sveltejs/kit/pull/4066))

## 1.0.0-next.282

### Patch Changes
Expand Down
4 changes: 2 additions & 2 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.282",
"version": "1.0.0-next.284",
"repository": {
"type": "git",
"url": "https://github.com/sveltejs/kit",
Expand All @@ -16,7 +16,7 @@
},
"devDependencies": {
"@playwright/test": "^1.17.1",
"@rollup/plugin-replace": "^3.0.0",
"@rollup/plugin-replace": "^4.0.0",
"@types/amphtml-validator": "^1.0.1",
"@types/cookie": "^0.4.1",
"@types/marked": "^4.0.1",
Expand Down
8 changes: 7 additions & 1 deletion packages/kit/src/runtime/client/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,19 @@ export class Router {

if (!a.href) return;

const is_svg_a_element = a instanceof SVGAElement;
const url = get_href(a);
const url_string = url.toString();
if (url_string === location.href) {
if (!location.hash) event.preventDefault();
return;
}

// Ignore if url does not have origin (e.g. `mailto:`, `tel:`.)
// MEMO: Without this condition, firefox will open mailer twice.
// See: https://github.com/sveltejs/kit/issues/4045
if (!is_svg_a_element && url.origin === 'null') return;

// Ignore if tag has
// 1. 'download' attribute
// 2. 'rel' attribute includes external
Expand All @@ -197,7 +203,7 @@ export class Router {
}

// Ignore if <a> has a target
if (a instanceof SVGAElement ? a.target.baseVal : a.target) return;
if (is_svg_a_element ? a.target.baseVal : a.target) return;

// Check if new url only differs by hash and use the browser default behavior in that case
// This will ensure the `hashchange` event is fired
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/server/page/load_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export async function load_node({

// generate __data.json files when prerendering
if (shadow.body && state.prerender) {
const pathname = `${event.url.pathname}/__data.json`;
const pathname = `${event.url.pathname.replace(/\/$/, '')}/__data.json`;

const dependency = {
response: new Response(undefined),
Expand Down
Loading

0 comments on commit 9e3c8ab

Please sign in to comment.