Skip to content

Don't refresh loader when a new gts file is added if the module has never been loaded#4245

Open
habdelra wants to merge 3 commits intomainfrom
cs-10474-dont-refresh-loader-when-a-gts-file-is-added-if-the-module
Open

Don't refresh loader when a new gts file is added if the module has never been loaded#4245
habdelra wants to merge 3 commits intomainfrom
cs-10474-dont-refresh-loader-when-a-gts-file-is-added-if-the-module

Conversation

@habdelra
Copy link
Contributor

Summary

  • Added isModuleLoaded() method to the Loader class that checks whether a module identifier exists in the internal modules map
  • Modified store.ts, card-service.ts, and file.ts to only trigger a loader reset when the changed executable file's module was already loaded
  • Net-new GTS/TS/JS files that have never been imported no longer cause a full loader reset and UI refresh

Fixes CS-10474

Test plan

  • Added 5 unit tests for isModuleLoaded:
    • Returns false for unimported modules
    • Returns true after import
    • Returns true for transitive dependencies
    • Works with executable extensions (.gts, .js, etc.)
    • Returns true for re-exported module dependencies
  • Verified red-green: tests fail without the implementation, pass with it
  • All 23 existing + new loader tests pass

🤖 Generated with Claude Code

…ever been loaded

When a new executable file (.gts/.ts/.js/.gjs) is written to a realm,
skip the expensive loader reset if the module was never imported. This
prevents unnecessary full UI refreshes in notebook-style workflows where
AI writes new code files sequentially.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e987bbdc2c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces unnecessary UI refreshes by avoiding loader resets when executable files change but their corresponding modules have never been loaded in the current session (CS-10474).

Changes:

  • Added Loader.isModuleLoaded() to detect whether a module is present in the loader’s internal module cache.
  • Updated invalidation handling and write paths to only reset/flush the loader when the changed executable module is already loaded.
  • Added unit tests covering isModuleLoaded() behavior for direct imports, dependencies, executable extensions, and re-exports.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/runtime-common/loader.ts Adds isModuleLoaded() API used to gate loader resets.
packages/host/tests/unit/loader-test.ts Adds unit tests for the new loader API.
packages/host/app/services/store.ts Avoids loader reset on executable invalidations for modules not already loaded.
packages/host/app/services/card-service.ts Only resets loader on save when the saved module was already loaded.
packages/host/app/resources/file.ts Only refreshes references for code change when the written module was already loaded.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link

Preview deployments

habdelra and others added 2 commits March 25, 2026 15:57
- Fix file.ts: capture isModuleLoaded BEFORE saveSource (which may reset
  the loader), so the check sees the pre-reset loader state
- Fix store.ts: use wasModuleLoaded() which checks both current and
  previous loader, handling the timing window where the save path resets
  the loader before the realm invalidation event arrives
- Add previousLoader tracking to LoaderService so module-loaded checks
  survive across loader resets within the same invalidation cycle
- Add try/catch to isModuleLoaded for non-URL identifiers

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
If the current loader has never encountered a module, no card was
rendered using it through this loader — there's nothing stale to
refresh. When the save path already called resetLoader(), the tracked
property change on the loader triggers Ember's reactivity, causing
re-renders that use the new loader to import updated code fresh.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link

Host Test Results

    1 files  ±0      1 suites  ±0   2h 10m 0s ⏱️ + 1m 21s
2 056 tests +5  2 041 ✅ +5  15 💤 ±0  0 ❌ ±0 
2 071 runs  +5  2 056 ✅ +5  15 💤 ±0  0 ❌ ±0 

Results for commit b8c147b. ± Comparison against base commit 0900ac6.

@habdelra habdelra requested a review from a team March 25, 2026 20:39
Copy link
Contributor

@backspace backspace left a comment

Choose a reason for hiding this comment

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

It would be nice to enforce this with a full-stack test but I don’t know how that would work

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants