MemberJunction / MemberJunction/MJ
Cached resource components don't refresh stale data on reattachment
- Dominant language
- TSQL
- Stars
- 29
- Forks
- 6
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 323
Description
## Problem
When components are cached by the tab container (both single-tab and multi-tab modes), navigating away and back reattaches the cached DOM element without notifying the component. If the user creates, edits, or deletes records while on a different nav item/tab, the cached component shows stale data until a manual page refresh.
**Example:** User navigates to Knowledge Hub > Configuration (component loads and caches). User navigates to the Credentials app and creates a new API key credential. User navigates back to Knowledge Hub > Configuration — the credential dropdown still shows the old list because the component was reattached from cache without reloading.
## Scope
This affects **all** `BaseResourceComponent` subclasses that are cached, not just Knowledge Hub. Any dashboard or resource component that displays data from entities the user might modify elsewhere will have this problem.
## Root Cause
The reattachment paths in `tab-container.component.ts` (`loadSingleResourceContent` line ~470 and `loadGoldenLayoutContent` line ~746) restore the cached wrapper element and component ref but never signal the component that it's back on screen.
## Possible Approaches
1. **`OnReattached()` lifecycle hook on `BaseResourceComponent`** — Tab container calls it on reattachment, components override to refresh. Simple and opt-in, but every component needs to implement it individually.
2. **MJGlobal entity event integration** — Components could subscribe to `GlobalEntityEvent` (save/delete events) and invalidate their cached data reactively. More automatic but higher complexity, and components would need to know which entities they depend on.
3. **Cache TTL / automatic invalidation** — The `ComponentCacheManager` could track a timestamp and force a reload if the component has been detached longer than a threshold. Blunt but simple.
4. **Hybrid** — Add `OnReattached()` as the hook, but also provide a base class utility (e.g., `this.WatchEntity('MJ: Credentials')`) that auto-subscribes to entity events and sets a dirty flag, so `OnReattached()` only reloads when something actually changed.
## Files of Interest
- `packages/Angular/Explorer/shared/src/lib/base-resource-component.ts` — base class
- `packages/Angular/Explorer/explorer-core/src/lib/shell/components/tabs/tab-container.component.ts` — reattachment paths (single-tab ~line 470, multi-tab ~line 746)
- `packages/Angular/Explorer/explorer-core/src/lib/shell/components/tabs/component-cache-manager.ts` — cache manager
## Related
This was discovered while adding credential support to the Knowledge Hub Vector Database configuration dashboard. The specific case was: creating a credential in the Credentials app, then navigating back to KH Config — the new credential didn't appear in the dropdown until a hard refresh.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Contributor guide
Assessment
This issue has not been assessed yet.