fix: restore inspector template hot reload
This commit is contained in:
parent
cbbb87cd2e
commit
ffba038b35
7 changed files with 232 additions and 35 deletions
23
index.js
23
index.js
|
|
@ -464,6 +464,29 @@ function renderTemplate(structureId, templateName, context) {
|
|||
return model.getTemplater(structureId).render(templateName, context);
|
||||
}
|
||||
|
||||
// Re-render one saved template instance with the JSON-safe values captured on
|
||||
// that instance when the page was first produced. This is deliberately a
|
||||
// platform endpoint rather than a user route: editing a template must not
|
||||
// replay a route handler (and its side effects) just to update the markup.
|
||||
app.post("/_bliss/render-template", (req, res) => {
|
||||
const structureId = String(req.body?.structureId ?? "");
|
||||
const templateId = String(req.body?.templateId ?? "");
|
||||
const template = model.getTemplate(templateId);
|
||||
if (!template || String(template.structure_id) !== structureId) {
|
||||
return res.status(404).send("Template not found");
|
||||
}
|
||||
|
||||
const structure = model.getStructure(structureId);
|
||||
const savedContext = model.getInspectableTemplateContext(
|
||||
req.body?.contextId,
|
||||
templateId,
|
||||
);
|
||||
if (!savedContext) return res.status(410).send("Template context expired; refresh the page");
|
||||
const context = { ...savedContext };
|
||||
context.route = makeRoute(structure);
|
||||
return res.type("html").send(renderTemplate(structureId, template.name, context));
|
||||
});
|
||||
|
||||
// Provenance for a rendered response: GET routes are re-embeddable, so they
|
||||
// carry the copy-embed snippet; other verbs don't.
|
||||
function sourceFor(route, req, templateName = null) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue