WIP: OOO streaming
This commit is contained in:
parent
9e4dcf4ce1
commit
0c8d20d432
1 changed files with 22 additions and 7 deletions
|
@ -1,17 +1,32 @@
|
||||||
import { createComponent, render, renderSlot, renderSuspense } from 'astro/runtime/server/index.js';
|
// astro-head-inject
|
||||||
|
import { createComponent, createHeadAndContent, render, renderSlot, renderSuspense, renderComponent, unescapeHTML } from 'astro/runtime/server/index.js';
|
||||||
|
|
||||||
let ids = new WeakMap();
|
let ids = new WeakMap();
|
||||||
export default createComponent({
|
const Suspense = createComponent({
|
||||||
factory(result, props, slots) {
|
factory(result, props, slots) {
|
||||||
const id = (ids.get(result) ?? -1) + 1;
|
const { id } = props;
|
||||||
ids.set(result, id);
|
|
||||||
let suspense = { status: 'pending' }
|
let suspense = { status: 'pending' }
|
||||||
suspense.value = renderSuspense(result, id, slots.default).then((result) => {
|
let promise = renderSuspense(result, id, slots.default).then((result) => {
|
||||||
suspense.status = 'fulfilled';
|
suspense.status = 'fulfilled';
|
||||||
return result;
|
return result;
|
||||||
})
|
});
|
||||||
|
suspense.value = promise;
|
||||||
result.suspense.set(id, suspense);
|
result.suspense.set(id, suspense);
|
||||||
|
|
||||||
return render`<astro-placeholder uid="${id}">${renderSlot(result, slots.fallback)}</astro-placeholder>`
|
return render`<astro-placeholder uid="${id}">${renderSlot(result, slots.fallback)}</astro-placeholder>`
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default createComponent({
|
||||||
|
factory(result, _props, slots) {
|
||||||
|
if (!ids.has(result.response)) {
|
||||||
|
ids.set(result.response, -1);
|
||||||
|
}
|
||||||
|
let id = ids.get(result.response) + 1;
|
||||||
|
ids.set(result.response, id);
|
||||||
|
return createHeadAndContent(
|
||||||
|
unescapeHTML(`<noscript><meta http-equiv="refresh" content="0;URL='${result._metadata.pathname}?noscript=1'"></noscript>`),
|
||||||
|
render`${renderComponent(result, 'Suspense', Suspense, { id }, slots)}`
|
||||||
|
)
|
||||||
|
},
|
||||||
|
propagation: 'self'
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in a new issue