Skip to content

Commit 3f3ad1a

Browse files
fixes
1 parent 90dd32b commit 3f3ad1a

File tree

9 files changed

+11
-48
lines changed

9 files changed

+11
-48
lines changed

documentation/docs/98-reference/.generated/server-warnings.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ A `hydratable` value with key `%key%` was created, but at least part of it was n
77
88
The `hydratable` was initialized in:
99
%stack%
10-
11-
The unresolved data is:
12-
%unresolved_data%
1310
```
1411

1512
The most likely cause of this is creating a `hydratable` in the `script` block of your component and then `await`ing

packages/svelte/messages/server-warnings/warnings.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
>
55
> The `hydratable` was initialized in:
66
> %stack%
7-
>
8-
> The unresolved data is:
9-
> %unresolved_data%
107
118
The most likely cause of this is creating a `hydratable` in the `script` block of your component and then `await`ing
129
the result inside a `svelte:boundary` with a `pending` snippet:

packages/svelte/src/internal/client/hydratable.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@ export function hydratable(key, fn) {
2121
}
2222

2323
const store = window.__svelte?.h;
24-
const unused_keys = window.__svelte?.uh;
2524
if (!store?.has(key)) {
26-
if (!unused_keys?.has(key)) {
27-
hydratable_missing_but_expected(key);
28-
}
25+
hydratable_missing_but_expected(key);
2926
return fn();
3027
}
3128

packages/svelte/src/internal/client/types.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ declare global {
77
__svelte?: {
88
/** hydratables */
99
h?: Map<string, unknown>;
10-
/** unused hydratable keys */
11-
uh?: Set<string>;
1210
};
1311
}
1412
}

packages/svelte/src/internal/server/renderer.js

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { BLOCK_CLOSE, BLOCK_OPEN } from './hydration.js';
1010
import { attributes } from './index.js';
1111
import { get_render_context, with_render_context, init_render_context } from './render-context.js';
1212
import { DEV } from 'esm-env';
13-
import { get_stack } from './dev.js';
1413

1514
/** @typedef {'head' | 'body'} RendererType */
1615
/** @typedef {{ [key in RendererType]: string }} AccumulatedContent */
@@ -578,22 +577,18 @@ export class Renderer {
578577
async #collect_hydratables() {
579578
const ctx = get_render_context().hydratable;
580579

581-
for (const [promise, key] of ctx.unresolved_promises) {
580+
for (const [_, key] of ctx.unresolved_promises) {
582581
// this is a problem -- it means we've finished the render but we're still waiting on a promise to resolve so we can
583582
// serialize it, so we're blocking the response on useless content.
584-
w.unresolved_hydratable(
585-
key,
586-
ctx.lookup.get(key)?.dev?.stack ?? '<missing stack trace>',
587-
await promise
588-
);
583+
w.unresolved_hydratable(key, ctx.lookup.get(key)?.dev?.stack ?? '<missing stack trace>');
589584
}
590585

591586
for (const comparison of ctx.comparisons) {
592587
// these reject if there's a mismatch
593588
await comparison;
594589
}
595590

596-
return await Renderer.#hydratable_block(ctx, []);
591+
return await Renderer.#hydratable_block(ctx);
597592
}
598593

599594
/**
@@ -652,10 +647,9 @@ export class Renderer {
652647

653648
/**
654649
* @param {HydratableContext} ctx
655-
* @param {string[]} unused_keys
656650
*/
657-
static async #hydratable_block(ctx, unused_keys) {
658-
if (ctx.lookup.size === 0 && unused_keys.length === 0) {
651+
static async #hydratable_block(ctx) {
652+
if (ctx.lookup.size === 0) {
659653
return null;
660654
}
661655

@@ -672,11 +666,11 @@ export class Renderer {
672666
{
673667
const r = (v) => Promise.resolve(v);
674668
const v = [${values.join(',')}];
675-
function d(i) {
669+
function d(i) {
676670
const value = v[i];
677671
return typeof value === 'function' ? value() : value;
678672
};
679-
const sv = window.__svelte ??= {};${Renderer.#used_hydratables(ctx.lookup)}${Renderer.#unused_hydratables(unused_keys)}
673+
const sv = window.__svelte ??= {};${Renderer.#used_hydratables(ctx.lookup)}
680674
}
681675
</script>`;
682676
}
@@ -693,16 +687,6 @@ export class Renderer {
693687
store.set(k, d(i));
694688
}`;
695689
}
696-
697-
/** @param {string[]} unused_keys */
698-
static #unused_hydratables(unused_keys) {
699-
if (unused_keys.length === 0) return '';
700-
return `
701-
const unused = sv.uh ??= new Set();
702-
for (const k of ${JSON.stringify(unused_keys)}) {
703-
unused.add(k);
704-
}`;
705-
}
706690
}
707691

708692
export class SSRState {

packages/svelte/src/internal/server/renderer.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { afterAll, beforeAll, describe, expect, test } from 'vitest';
22
import { Renderer, SSRState } from './renderer.js';
33
import type { Component } from 'svelte';
44
import { disable_async_mode_flag, enable_async_mode_flag } from '../flags/index.js';
5-
import { uneval } from 'devalue';
65

76
test('collects synchronous body content by default', () => {
87
const component = (renderer: Renderer) => {

packages/svelte/src/internal/server/warnings.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,16 @@ var normal = 'font-weight: normal';
1010
*
1111
* The `hydratable` was initialized in:
1212
* %stack%
13-
*
14-
* The unresolved data is:
15-
* %unresolved_data%
1613
* @param {string} key
1714
* @param {string} stack
18-
* @param {string} unresolved_data
1915
*/
20-
export function unresolved_hydratable(key, stack, unresolved_data) {
16+
export function unresolved_hydratable(key, stack) {
2117
if (DEV) {
2218
console.warn(
2319
`%c[svelte] unresolved_hydratable\n%cA \`hydratable\` value with key \`${key}\` was created, but at least part of it was not used during the render.
2420
2521
The \`hydratable\` was initialized in:
26-
${stack}
27-
28-
The unresolved data is:
29-
${unresolved_data}\nhttps://svelte.dev/e/unresolved_hydratable`,
22+
${stack}\nhttps://svelte.dev/e/unresolved_hydratable`,
3023
bold,
3124
normal
3225
);

packages/svelte/tests/runtime-legacy/shared.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ declare global {
107107
var __svelte:
108108
| {
109109
h?: Map<string, unknown>;
110-
uh?: Set<string>;
111110
}
112111
| undefined;
113112
}
@@ -127,7 +126,6 @@ beforeAll(() => {
127126

128127
beforeEach(() => {
129128
delete globalThis?.__svelte?.h;
130-
delete globalThis?.__svelte?.uh;
131129
});
132130

133131
afterAll(() => {

packages/svelte/tests/runtime-runes/samples/hydratable-unused-keys/_config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default test({
1515
},
1616

1717
async test({ assert, target }) {
18-
// let it hydrate and resolve the promise on the client
18+
// make sure the hydratable promise on the client has a chance to run and reject (it shouldn't, because the server data should be used)
1919
await tick();
2020

2121
assert.htmlEqual(

0 commit comments

Comments
 (0)