Replies: 2 comments 2 replies
-
This would allow for something like this to exist: // routes/index.tsx
import { content } from "../utils/content.ts";
export default function index() {
return (
<article>
{content`content-key`}
</article>
);
} // utils/content.ts
let content: Record<string, string>;
export function content(strings: TemplateStringsArray) {
return content[strings[0]] || "no_content";
}
export function setup(new_content: Record<string, string>) {
content = new_content;
} // plugings/cms.tsx
import { setup } from "../utils/content.ts";
export default function CMSPlugin(): Plugin {
return {
name: "cms-plugin",
async render(ctx) {
const content = await fetch_content();
setup(content);
ctx.render();
return {};
},
};
} A really simple workaround for this specific example would just to run the What if we only want to pull in the content keys we're using and content injections are scattered around, nested in components, or exist inside islands? Content injections in islands are easy as we can just pass a hydration script, and pass the resolved content to the state of that script (just like the twind plugin). The server-side generated content injections can be accomplished by making two render passes: one to build the list of keys that need to be fetched and the second to render the resolved content in. I don't really like the idea of running the render pass twice so there may be a better solution or might introduce another DX decision to work out, but that is the only way I could think of accomplishing this while keeping this discussion focused on allowing the plugin's render to be async and not introduce any other features. |
Beta Was this translation helpful? Give feedback.
-
FYI: Since this question was asked we added |
Beta Was this translation helpful? Give feedback.
-
Currently a plugin's render function must be sync so we run into a roadblock if a plugin's render function needs to resolve an async operation (i.e. hitting CMS api, etc) before setting the state of a hydration script or before we call the context's render function.
Any ideas how to get around this or how the plugin render fuction could be updated to allow for it to be async?
Beta Was this translation helpful? Give feedback.
All reactions