Skip to content

fix: persist widget build cache across restarts#61

Merged
homanp merged 1 commit intohomanp:mainfrom
mehdiraized:fix/persist-widget-build-cache
Mar 29, 2026
Merged

fix: persist widget build cache across restarts#61
homanp merged 1 commit intohomanp:mainfrom
mehdiraized:fix/persist-widget-build-cache

Conversation

@mehdiraized
Copy link
Copy Markdown
Contributor

@mehdiraized mehdiraized commented Mar 28, 2026

What

Persist widget build artifacts to disk and restore them on demand instead of rebuilding every widget after every server/app restart.

This change updates the widget runner to:

  • cache each built widget dist/ output under the app data directory, keyed by the widget source hash
  • restore the widget server from that cached build on the next request after restart
  • invalidate old cache entries automatically when widget files change
  • validate the shared base template more strictly before reusing it
  • rebuild the base template if a previous install was incomplete

Why

Today widget builds only live in memory and temporary directories, so every restart forces all widgets to rebuild from scratch.

That has two user-facing problems:

  • dashboards spend time in Building widget... on every app launch even when nothing changed
  • partially installed or corrupted base templates can be reused, which can lead to intermittent ERR_MODULE_NOT_FOUND failures during widget builds

Persisting build output fixes the repeated rebuild behavior, and tightening template validation makes the build pipeline more reliable.

Test plan

  • Tests pass locally
  • Tested manually

Manual verification:

  • started the app/server against a real widget database
  • requested a widget route and confirmed the first request built the widget normally
  • restarted the server and requested the same widget again
  • confirmed the widget was restored from cache instead of rebuilt
  • confirmed the runner logged Restored cached widget ... on the second run

Note

Medium Risk
Introduces disk-backed caching and restore logic for widget build artifacts, changing build/serve lifecycle and filesystem interactions; failures could lead to stale/invalid builds being served or unexpected rebuild loops.

Overview
Adds a persistent widget build cache under the app data directory, keyed by a hash of widget source files plus template/cache versions, and updates the build pipeline to copy dist/ into that cache and serve from it instead of a temp sandbox.

ensureWidget now attempts to restore and serve a cached build on demand after restarts, falling back to a rebuild and purging the cache entry if restore fails; runtime/sandbox cleanup is centralized via disposeWidgetRuntime.

Base template reuse is tightened with stricter validation (required UI files and packages) and automatic reinstallation if the template directory is incomplete.

Written by Cursor Bugbot for commit 3abf73b. Configure here.

@github-actions github-actions bot added the contributor:verified Contributor passed trust analysis. label Mar 28, 2026
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

@homanp
Copy link
Copy Markdown
Owner

homanp commented Mar 29, 2026

@mehdiraized mind looking at the PR comments?

@homanp homanp merged commit 7a62aa0 into homanp:main Mar 29, 2026
6 checks passed
@mehdiraized
Copy link
Copy Markdown
Contributor Author

@mehdiraized mind looking at the PR comments?

Sure, I’ll check the Cursor comments and make any needed changes, then update the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor:verified Contributor passed trust analysis.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants