Skip to content

Commit fbca8f5

Browse files
authored
Merge branch 'main' into issue-14387
2 parents 7331cba + b903e4d commit fbca8f5

File tree

37 files changed

+582
-29
lines changed

37 files changed

+582
-29
lines changed

.changeset/forty-dots-punch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: enable redirects from queries

.changeset/lazy-boats-stay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: remove empty nodes from serialized server load data

.changeset/slow-chicken-serve.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

documentation/docs/20-core-concepts/60-remote-functions.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,59 @@ Any query can be re-fetched via its `refresh` method, which retrieves the latest
172172
173173
> [!NOTE] Queries are cached while they're on the page, meaning `getPosts() === getPosts()`. This means you don't need a reference like `const posts = getPosts()` in order to update the query.
174174
175+
## query.batch
176+
177+
`query.batch` works like `query` except that it batches requests that happen within the same macrotask. This solves the so-called n+1 problem: rather than each query resulting in a separate database call (for example), simultaneous queries are grouped together.
178+
179+
On the server, the callback receives an array of the arguments the function was called with. It must return a function of the form `(input: Input, index: number) => Output`. SvelteKit will then call this with each of the input arguments to resolve the individual calls with their results.
180+
181+
```js
182+
/// file: weather.remote.js
183+
// @filename: ambient.d.ts
184+
declare module '$lib/server/database' {
185+
export function sql(strings: TemplateStringsArray, ...values: any[]): Promise<any[]>;
186+
}
187+
// @filename: index.js
188+
// ---cut---
189+
import * as v from 'valibot';
190+
import { query } from '$app/server';
191+
import * as db from '$lib/server/database';
192+
193+
export const getWeather = query.batch(v.string(), async (cities) => {
194+
const weather = await db.sql`
195+
SELECT * FROM weather
196+
WHERE city = ANY(${cities})
197+
`;
198+
const lookup = new Map(weather.map(w => [w.city, w]));
199+
200+
return (city) => lookup.get(city);
201+
});
202+
```
203+
204+
```svelte
205+
<!--- file: Weather.svelte --->
206+
<script>
207+
import CityWeather from './CityWeather.svelte';
208+
import { getWeather } from './weather.remote.js';
209+
210+
let { cities } = $props();
211+
let limit = $state(5);
212+
</script>
213+
214+
<h2>Weather</h2>
215+
216+
{#each cities.slice(0, limit) as city}
217+
<h3>{city.name}</h3>
218+
<CityWeather weather={await getWeather(city.id)} />
219+
{/each}
220+
221+
{#if cities.length > limit}
222+
<button onclick={() => limit += 5}>
223+
Load more
224+
</button>
225+
{/if}
226+
```
227+
175228
## form
176229
177230
The `form` function makes it easy to write data to the server. It takes a callback that receives the current [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)...

documentation/docs/25-build-and-deploy/80-adapter-netlify.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ New projects will use the current Node LTS version by default. However, if you'r
5050

5151
## Netlify Edge Functions
5252

53-
SvelteKit supports [Netlify Edge Functions](https://docs.netlify.com/netlify-labs/experimental-features/edge-functions/). If you pass the option `edge: true` to the `adapter` function, server-side rendering will happen in a Deno-based edge function that's deployed close to the site visitor. If set to `false` (the default), the site will deploy to Node-based Netlify Functions.
53+
SvelteKit supports [Netlify Edge Functions](https://docs.netlify.com/build/edge-functions/overview/). If you pass the option `edge: true` to the `adapter` function, server-side rendering will happen in a Deno-based edge function that's deployed close to the site visitor. If set to `false` (the default), the site will deploy to Node-based Netlify Functions.
5454

5555
```js
5656
/// file: svelte.config.js

packages/adapter-node/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# @sveltejs/adapter-node
22

3+
## 5.3.2
4+
### Patch Changes
5+
6+
7+
- fix: bump bundled sirv version to 3.0.2 ([#14385](https://github.com/sveltejs/kit/pull/14385))
8+
9+
- Updated dependencies [[`e6c3171`](https://github.com/sveltejs/kit/commit/e6c317150d330413a7691c1b00dc94ce121fdb89)]:
10+
- @sveltejs/kit@2.38.0
11+
312
## 5.3.1
413
### Patch Changes
514

packages/adapter-node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sveltejs/adapter-node",
3-
"version": "5.3.1",
3+
"version": "5.3.2",
44
"description": "Adapter for SvelteKit apps that generates a standalone Node server",
55
"keywords": [
66
"adapter",

packages/kit/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @sveltejs/kit
22

3+
## 2.38.0
4+
### Minor Changes
5+
6+
7+
- feat: add new remote function `query.batch` ([#14272](https://github.com/sveltejs/kit/pull/14272))
8+
39
## 2.37.1
410
### Patch Changes
511

packages/kit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sveltejs/kit",
3-
"version": "2.37.1",
3+
"version": "2.38.0",
44
"description": "SvelteKit is the fastest way to build Svelte apps",
55
"keywords": [
66
"framework",

packages/kit/src/exports/internal/remote-functions.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@ export function validate_remote_functions(module, file) {
1010
}
1111

1212
for (const name in module) {
13-
const type = module[name]?.__?.type;
13+
const type = /** @type {import('types').RemoteInfo['type']} */ (module[name]?.__?.type);
1414

15-
if (type !== 'form' && type !== 'command' && type !== 'query' && type !== 'prerender') {
15+
if (
16+
type !== 'form' &&
17+
type !== 'command' &&
18+
type !== 'query' &&
19+
type !== 'query_batch' &&
20+
type !== 'prerender'
21+
) {
1622
throw new Error(
1723
`\`${name}\` exported from ${file} is invalid — all exports from this file must be remote functions`
1824
);

0 commit comments

Comments
 (0)