Add auto-reload for HTML artifacts when dependencies change

HTML artifacts can read other artifacts via getArtifact() and attachments.
When any artifact is created, updated, rewritten, or deleted, all HTML
artifacts now automatically reload to reflect the latest data.

Changes:
- Add reloadAllHtmlArtifacts() method to ArtifactsPanel
- Call reload after all artifact mutations (create/update/rewrite/delete)
- Make HtmlArtifact.sandboxIframeRef and executeContent() public
- Update runtime providers before re-executing HTML content

This ensures HTML artifacts always display current data from their dependencies.
This commit is contained in:
Mario Zechner
2025-10-18 00:10:23 +02:00
parent 2a7ccf0fcb
commit 92ce5a342f
2 changed files with 26 additions and 2 deletions
@@ -23,7 +23,7 @@ export class HtmlArtifact extends ArtifactElement {
private logs: Array<{ type: "log" | "error"; text: string }> = [];
// Refs for DOM elements
private sandboxIframeRef: Ref<SandboxIframe> = createRef();
public sandboxIframeRef: Ref<SandboxIframe> = createRef();
private consoleRef: Ref<Console> = createRef();
@state() private viewMode: "preview" | "code" = "preview";
@@ -76,7 +76,7 @@ export class HtmlArtifact extends ArtifactElement {
}
}
private executeContent(html: string) {
public executeContent(html: string) {
const sandbox = this.sandboxIframeRef.value;
if (!sandbox) return;