pull/16797/head
Rich Harris 6 days ago
parent 27f6aa401c
commit 75836424ed

@ -56,11 +56,10 @@ export class Renderer {
#parent;
/**
* Asynchronous work associated with this renderer. `initial` is the promise from the function
* this renderer was passed to (if that function was async)
* @type {{ initial: Promise<void> | undefined }}
* Asynchronous work associated with this renderer
* @type {Promise<void> | undefined}
*/
promises = { initial: undefined };
promise = undefined;
/**
* State which is associated with the content tree as a whole.
@ -138,7 +137,7 @@ export class Renderer {
}
// just to avoid unhandled promise rejections -- we'll end up throwing in `collect_async` if something fails
result.catch(() => {});
child.promises.initial = result;
child.promise = result;
}
return child;
@ -280,7 +279,7 @@ export class Renderer {
copy() {
const copy = new Renderer(this.global, this.#parent);
copy.#out = this.#out.map((item) => (item instanceof Renderer ? item.copy() : item));
copy.promises = this.promises;
copy.promise = this.promise;
return copy;
}
@ -302,7 +301,7 @@ export class Renderer {
}
return item;
});
this.promises = other.promises;
this.promise = other.promise;
this.type = other.type;
}
@ -499,10 +498,10 @@ export class Renderer {
if (typeof item === 'string') {
content[current_type] += item;
} else {
if (item.promises.initial) {
if (item.promise) {
// this represents the async function that's modifying this renderer.
// we can't do anything until it's done and we know our `out` array is complete.
await item.promises.initial;
await item.promise;
}
await Renderer.#collect_content_async(item.#out, item.type, content);

@ -112,13 +112,13 @@ test('subsume replaces tree content and state from other', () => {
b.global.css.add({ hash: 'h', code: 'c' });
b.global.set_title('Title', [1]);
b.local.select_value = 'B';
b.promises.initial = Promise.resolve();
b.promise = Promise.resolve();
a.subsume(b);
expect(a.type).toBe('body');
expect(a.local.select_value).toBe('B');
expect(a.promises).toBe(b.promises);
expect(a.promise).toBe(b.promise);
});
test('subsume refuses to switch modes', () => {
@ -136,7 +136,7 @@ test('subsume refuses to switch modes', () => {
b.global.css.add({ hash: 'h', code: 'c' });
b.global.set_title('Title', [1]);
b.local.select_value = 'B';
b.promises.initial = Promise.resolve();
b.promise = Promise.resolve();
expect(() => a.subsume(b)).toThrow(
"invariant: A renderer cannot switch modes. If you're seeing this, there's a compiler bug. File an issue!"

Loading…
Cancel
Save