pull/16748/head
S. Elliott Johnson 4 weeks ago
parent 77c53d12c0
commit fc84ada257

@ -1,5 +1,13 @@
<!-- This file is generated by scripts/process-messages/index.js. Do not edit! --> <!-- This file is generated by scripts/process-messages/index.js. Do not edit! -->
### async_in_sync
```
Encountered asynchronous work while rendering synchronously.
```
You (or the framework you're using) used `render` with an async component. Either use `renderAsync` or wrap the async component in a `svelte:boundary` with a `pending` snippet.
### lifecycle_function_unavailable ### lifecycle_function_unavailable
``` ```

@ -0,0 +1,5 @@
## async_in_sync
> Encountered asynchronous work while rendering synchronously.
You (or the framework you're using) used `render` with an async component. Either use `renderAsync` or wrap the async component in a `svelte:boundary` with a `pending` snippet.

@ -2,6 +2,18 @@
export * from '../shared/errors.js'; export * from '../shared/errors.js';
/**
* Encountered asynchronous work while rendering synchronously.
* @returns {never}
*/
export function async_in_sync() {
const error = new Error(`async_in_sync\nEncountered asynchronous work while rendering synchronously.\nhttps://svelte.dev/e/async_in_sync`);
error.name = 'Svelte error';
throw error;
}
/** /**
* `%name%(...)` is not available on the server * `%name%(...)` is not available on the server
* @param {string} name * @param {string} name

@ -1,3 +1,6 @@
import { pop, push, set_ssr_context, ssr_context } from './context.js';
import * as e from './errors.js';
/** @typedef {'head' | 'body'} PayloadType */ /** @typedef {'head' | 'body'} PayloadType */
/** @typedef {{ [key in PayloadType]: string }} AccumulatedContent */ /** @typedef {{ [key in PayloadType]: string }} AccumulatedContent */
/** @typedef {{ start: number, end: number, fn: (content: AccumulatedContent) => AccumulatedContent | Promise<AccumulatedContent> }} Compaction */ /** @typedef {{ start: number, end: number, fn: (content: AccumulatedContent) => AccumulatedContent | Promise<AccumulatedContent> }} Compaction */
@ -9,8 +12,6 @@
* @typedef {string | Payload} PayloadItem * @typedef {string | Payload} PayloadItem
*/ */
import { pop, push, set_ssr_context, ssr_context } from './context.js';
/** /**
* Payloads are basically a tree of `string | Payload`s, where each `Payload` in the tree represents * Payloads are basically a tree of `string | Payload`s, where each `Payload` in the tree represents
* work that may or may not have completed. A payload can be {@link collect}ed to aggregate the * work that may or may not have completed. A payload can be {@link collect}ed to aggregate the
@ -198,8 +199,9 @@ export class Payload {
*/ */
subsume(other) { subsume(other) {
if (this.global.mode !== other.global.mode) { if (this.global.mode !== other.global.mode) {
// TODO message - this should be impossible though throw new Error(
throw new Error('invariant: a payload cannot switch modes'); "invariant: A payload cannot switch modes. If you're seeing this, there's a compiler bug. File an issue!"
);
} }
this.global.subsume(other.global); this.global.subsume(other.global);
@ -228,7 +230,9 @@ export class Payload {
const content = Payload.#collect_content(to_compact, type); const content = Payload.#collect_content(to_compact, type);
const transformed_content = fn(content); const transformed_content = fn(content);
if (transformed_content instanceof Promise) { if (transformed_content instanceof Promise) {
throw new Error('invariant: should never reach this'); throw new Error(
"invariant: Somehow you've encountered asynchronous work while rendering synchronously. If you're seeing this, there's a compiler bug. File an issue!"
);
} else { } else {
Payload.#push_accumulated_content(child, transformed_content); Payload.#push_accumulated_content(child, transformed_content);
} }
@ -281,8 +285,7 @@ export class Payload {
const result = render(child_payload); const result = render(child_payload);
if (result instanceof Promise) { if (result instanceof Promise) {
if (this.global.mode === 'sync') { if (this.global.mode === 'sync') {
// TODO more-proper error e.async_in_sync();
throw new Error('Encountered an asynchronous component while rendering synchronously');
} }
// just to avoid unhandled promise rejections -- we'll end up throwing in `collect_async` if something fails // just to avoid unhandled promise rejections -- we'll end up throwing in `collect_async` if something fails
result.catch(() => {}); result.catch(() => {});

Loading…
Cancel
Save