Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions packages/kit/test/apps/async/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# sv

Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli).

## Creating a project

If you're seeing this, you've probably already done this step. Congrats!

```sh
# create a new project in the current directory
npx sv create

# create a new project in my-app
npx sv create my-app
```

## Developing

Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:

```sh
npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open
```

## Building

To create a production version of your app:

```sh
npm run build
```

You can preview the production build with `npm run preview`.

> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
25 changes: 25 additions & 0 deletions packages/kit/test/apps/async/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "test-async",
"private": true,
"version": "0.0.1",
"type": "module",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"prepare": "svelte-kit sync || echo ''",
"check": "svelte-kit sync && tsc && svelte-check",
"test": "pnpm test:dev && pnpm test:build",
"test:dev": "DEV=true playwright test",
"test:build": "playwright test"
},
"devDependencies": {
"@sveltejs/kit": "workspace:^",
"@sveltejs/vite-plugin-svelte": "catalog:",
"svelte": "catalog:",
"svelte-check": "catalog:",
"typescript": "^5.5.4",
"valibot": "catalog:",
"vite": "catalog:"
}
}
11 changes: 11 additions & 0 deletions packages/kit/test/apps/async/playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import process from 'node:process';
import { config } from '../../utils.js';
import { defineConfig } from '@playwright/test';

export default defineConfig({
...config,
webServer: {
command: process.env.DEV ? `pnpm dev` : `pnpm build && pnpm preview`,
port: process.env.DEV ? 5173 : 4173
}
});
11 changes: 11 additions & 0 deletions packages/kit/test/apps/async/src/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>
9 changes: 9 additions & 0 deletions packages/kit/test/apps/async/src/hooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Foo } from '$lib';

/** @type {import("@sveltejs/kit").Transport} */
export const transport = {
Foo: {
encode: (value) => value instanceof Foo && [value.message],
decode: ([message]) => new Foo(message)
}
};
11 changes: 11 additions & 0 deletions packages/kit/test/apps/async/src/hooks.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** @type {import('@sveltejs/kit').HandleValidationError} */
export const handleValidationError = ({ issues }) => {
return { message: issues[0].message };
};

/** @type {import('@sveltejs/kit').HandleServerError} */
export const handleError = ({ error: e, status, message }) => {
const error = /** @type {Error} */ (e);

return { message: `${error.message} (${status} ${message})` };
};
1 change: 1 addition & 0 deletions packages/kit/test/apps/async/src/lib/assets/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions packages/kit/test/apps/async/src/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class Foo {
constructor(message) {
this.message = message;
}

bar() {
return this.message + '!';
}
}
37 changes: 37 additions & 0 deletions packages/kit/test/apps/async/src/routes/+error.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<script>
import { page } from '$app/state';

console.log('hi');
</script>

<svelte:head>
<title>Custom error page: {page.error.message}</title>
</svelte:head>

<h1>{page.status}</h1>

<p id="message">This is your custom error page saying: "<b>{page.error.message}</b>"</p>

<style>
h1,
p {
margin: 0 auto;
}

h1 {
font-size: 2.8em;
font-weight: 700;
margin: 0 0 0.5em 0;
color: red;
}

p {
margin: 1em auto;
}

@media (min-width: 480px) {
h1 {
font-size: 4em;
}
}
</style>
9 changes: 9 additions & 0 deletions packages/kit/test/apps/async/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script lang="ts">
import { setup } from '../../../../setup.js';

const { children } = $props();

setup();
</script>

{@render children?.()}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@
</script>

<p id="echo-result">{data.echo_result}</p>
<!-- TODO use await here once async lands -->
{#if browser}
<p id="count-result">
{#await count then result}{result}{/await} / {count.current} ({count.loading})
{await count} / {count.current} ({count.loading})
</p>
<!-- this is just here to check that it is re-requested after the command -->
{#await add({ a: 2, b: 2 }) then result}{result}{/await}
{await add({ a: 2, b: 2 })}
{/if}
<p id="command-result">{command_result}</p>

Expand Down Expand Up @@ -110,4 +109,8 @@
</button>
<button id="resolve-deferreds" onclick={() => resolve_deferreds()}>Resolve Deferreds</button>

<a href="/remote/event">/remote/event</a>
<!--
TODO: preloading currently breaks this, because the fork is run on the current route
or something like that. Remove `data-sveltekit-preload-data="off"` when fixed.
-->
<a href="/remote/event" data-sveltekit-preload-data="off">/remote/event</a>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<script>
<script lang="ts">
import {
get_todo,
set_todo_title_server_refresh,
Expand All @@ -17,13 +17,19 @@
<ul>
{#each todos as { id, promise }, idx (idx)}
<li>
{#await promise}
<span id="batch-result-{idx + 1}">Loading todo {id}...</span>
{:then todo}
<span id="batch-result-{idx + 1}">{todo.title}</span>
{:catch error}
<span id="batch-result-{idx + 1}">Error loading todo {id}: {error.body.message}</span>
{/await}
<svelte:boundary>
<span id="batch-result-{idx + 1}">{(await promise).title}</span>

{#snippet pending()}
<span id="batch-result-{idx + 1}">Loading todo {id}...</span>
{/snippet}

{#snippet failed(error)}
<span id="batch-result-{idx + 1}"
>Error loading todo {id}: {(error as any).body.message}</span
>
{/snippet}
</svelte:boundary>
</li>
{/each}
</ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
import { get_event } from './data.remote.js';

const event = await get_event();
</script>

<p data-id="route">route: {event.route.id}</p>
<p data-id="pathname">pathname: {event.url.pathname}</p>
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

<p>message.current: {message.current}</p>

<!-- TODO use await here once async lands -->
{#await message then m}
<p>await get_message(): {m}</p>
{/await}
<p>await get_message(): {await message}</p>

<hr />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
});
</script>

<!-- TODO use await here once async lands -->
{#await data then { a, b, c }}
<p>a: {a}</p>
<p>b: {b}</p>
<p>c: {c}</p>
{/await}
<p>a: {(await data).a}</p>
<p>b: {(await data).b}</p>
<p>c: {(await data).c}</p>

<hr />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@

<p>number.current: {number.current}</p>

<!-- TODO use await here once async lands -->
{#await number then n}
<p>await get_number(): {n}</p>
{/await}
<p>await get_number(): {await number}</p>

<hr />

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
import { total } from './data.remote.js';
</script>

<h1>{await total()}</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script>
import { page } from '$app/state';
import { layoutRedirect } from '../redirect.remote';

let { children } = $props();
</script>

<p id="layout-query">
on page {await layoutRedirect(page.url.pathname)} (== {page.url.pathname})
</p>

{@render children()}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
import { pageRedirect } from '../redirect.remote';
</script>

<svelte:boundary>
{await pageRedirect()}
<p>should never see this</p>
</svelte:boundary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
import { greeting } from './data.remote.js';
</script>

<h1>{(await greeting()).bar()}</h1>
3 changes: 3 additions & 0 deletions packages/kit/test/apps/async/static/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# allow crawling everything by default
User-agent: *
Disallow:
16 changes: 16 additions & 0 deletions packages/kit/test/apps/async/svelte.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** @type {import('@sveltejs/kit').Config} */
const config = {
compilerOptions: {
experimental: {
async: true
}
},

kit: {
experimental: {
remoteFunctions: true
}
}
};

export default config;
Loading
Loading