I have lost the plot

pull/16748/head
S. Elliott Johnson 3 weeks ago
parent 33329d49cd
commit f6d3894ea8

@ -15,3 +15,11 @@ You (or the framework you're using) used `render` with an async component. Eithe
```
Certain methods such as `mount` cannot be invoked while running in a server context. Avoid calling them eagerly, i.e. not during render.
### missing_experimental_flag
```
Attempted to use `renderAsync` without `experimental.async` enabled
```
Set `experimental.async: true` in your compiler options to use async server rendering.

@ -3,3 +3,9 @@
> 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.
## missing_experimental_flag
> Attempted to use `renderAsync` without `experimental.async` enabled
Set `experimental.async: true` in your compiler options to use async server rendering.

@ -14,6 +14,18 @@ export function async_in_sync() {
throw error;
}
/**
* Attempted to use `renderAsync` without `experimental.async` enabled
* @returns {never}
*/
export function missing_experimental_flag() {
const error = new Error(`missing_experimental_flag\nAttempted to use \`renderAsync\` without \`experimental.async\` enabled\nhttps://svelte.dev/e/missing_experimental_flag`);
error.name = 'Svelte error';
throw error;
}
/**
* `%name%(...)` is not available on the server
* @param {string} name

@ -20,6 +20,8 @@ import { validate_store } from '../shared/validate.js';
import { is_boolean_attribute, is_raw_text_element, is_void } from '../../utils.js';
import { Payload, TreeState } from './payload.js';
import { abort } from './abort-signal.js';
import { async_mode_flag } from '../flags/index.js';
import * as e from './errors.js';
// https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
// https://infra.spec.whatwg.org/#noncharacter
@ -116,6 +118,10 @@ export function render(component, options = {}) {
* @returns {Promise<RenderOutput>}
*/
export async function render_async(component, options = {}) {
if (!async_mode_flag) {
e.missing_experimental_flag();
}
var previous_context = ssr_context;
try {

@ -70,7 +70,7 @@ test('creating an async child in a sync context throws', () => {
await Promise.resolve();
$$payload.push('x');
})
).toThrow('Encountered an asynchronous component while rendering synchronously');
).toThrow('async_in_sync');
});
test('collect_async allows awaiting payload to get aggregated content', async () => {
@ -200,7 +200,9 @@ test('subsume refuses to switch modes', () => {
b.local.select_value = 'B';
b.promises.initial = Promise.resolve();
expect(() => a.subsume(b)).toThrow('invariant: a payload cannot switch modes');
expect(() => a.subsume(b)).toThrow(
"invariant: A payload cannot switch modes. If you're seeing this, there's a compiler bug. File an issue!"
);
});
test('TreeState uid generator uses prefix and is shared by copy()', () => {

@ -167,6 +167,7 @@ export function runtime_suite(runes: boolean) {
}
if (variant === 'async-ssr') {
if (!runes) return 'no-test';
if (
(config.mode && !config.mode.includes('async-server')) ||
(!config.test_ssr &&
@ -334,7 +335,7 @@ async function run_test_variant(
// ssr into target
const SsrSvelteComponent = (await import(`${cwd}/_output/server/main.svelte.js`)).default;
const rendered =
variant === 'async-ssr' || variant === 'hydrate'
variant === 'async-ssr' || (variant === 'hydrate' && compileOptions.experimental?.async)
? await renderAsync(SsrSvelteComponent, {
props: config.server_props ?? config.props ?? {},
idPrefix: config.id_prefix

@ -3,5 +3,5 @@ import { test } from '../../test';
export default test({
mode: ['server'],
error: 'Encountered an asynchronous component while rendering synchronously'
error: 'async_in_sync'
});

@ -59,6 +59,8 @@ const { test, run } = suite_with_variants<SSRTest, 'sync' | 'async', CompileOpti
...config.compileOptions
};
console.log(compile_options);
if (!config.load_compiled) {
await compile_directory(test_dir, 'server', compile_options);
}

Loading…
Cancel
Save