abort synchronously in SSR

pull/16266/head
Rich Harris 3 months ago
parent c4a948def3
commit 93125942d7

@ -2,7 +2,6 @@
import { current_component } from './internal/server/context.js';
import { noop } from './internal/shared/utils.js';
import * as e from './internal/server/errors.js';
import { STALE_REACTION } from '#client/constants';
/** @param {() => void} fn */
export function onDestroy(fn) {
@ -36,20 +35,7 @@ export function unmount() {
export async function tick() {}
/** @type {AbortController | null} */
let controller = null;
export function getAbortSignal() {
if (controller === null) {
const c = (controller = new AbortController());
queueMicrotask(() => {
c.abort(STALE_REACTION);
controller = null;
});
}
return controller.signal;
}
export { getAbortSignal } from './internal/server/abort-signal.js';
export { getAllContexts, getContext, hasContext, setContext } from './internal/server/context.js';

@ -0,0 +1,15 @@
import { STALE_REACTION } from '#client/constants';
/** @type {AbortController | null} */
export let controller = null;
export function abort() {
if (controller !== null) {
controller.abort(STALE_REACTION);
controller = null;
}
}
export function getAbortSignal() {
return (controller ??= new AbortController()).signal;
}

@ -18,6 +18,7 @@ import { validate_store } from '../shared/validate.js';
import { is_boolean_attribute, is_raw_text_element, is_void } from '../../utils.js';
import { reset_elements } from './dev.js';
import { Payload } from './payload.js';
import { abort } from './abort-signal.js';
// https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
// https://infra.spec.whatwg.org/#noncharacter
@ -66,6 +67,7 @@ export let on_destroy = [];
* @returns {RenderOutput}
*/
export function render(component, options = {}) {
try {
const payload = new Payload(options.idPrefix ? options.idPrefix + '-' : '');
const prev_on_destroy = on_destroy;
@ -110,6 +112,9 @@ export function render(component, options = {}) {
html: payload.out,
body: payload.out
};
} finally {
abort();
}
}
/**

Loading…
Cancel
Save