Skip to content

fix(factories): refetch on profile switch + add activeProfileId to route deps#47

Merged
8144225309 merged 1 commit into
mainfrom
fix/factories-refetch-on-profile-switch
May 28, 2026
Merged

fix(factories): refetch on profile switch + add activeProfileId to route deps#47
8144225309 merged 1 commit into
mainfrom
fix/factories-refetch-on-profile-switch

Conversation

@8144225309

Copy link
Copy Markdown
Owner

Problem

Switching the wallet's active node via the NodePicker dropdown could leave the Factories list empty even though the new node's plugin had factories — surfaced during the post-#46 orchestrator audit (tracked as bug #157).

The audit reproduced it deterministically:

  • Active profile = ss-demo-lsp on /bookkeeper
  • Switch dropdown → ss-demo-client
  • Navigate to /factories
  • Wallet shows All=0 / LSP=0 / Client=0

Meanwhile CLI factory-list on the client returned 3 factories (e2ebf4f0, d607, a823931a), and the Dashboard correctly showed 1 channel from the client POV (confirming backend rebinding worked).

Root cause

Two cooperating bugs in the post-switch / route-data plumbing:

  1. NodePicker.handleSwitchNode (apps/frontend/src/components/ui/NodePicker/NodePicker.tsx:63-73)
    The background refresh after a profile switch fetched only one section's data, chosen by the current pathname:

    const bgRefresh = pathname.includes('/bookkeeper')
      ? BookkeeperService.fetchBKPRData()
      : pathname.includes('/factories')
        ? FactoriesService.fetchFactoriesData()
        : CLNService.fetchCLNData();

    Switch profile on /bookkeeper → only BKPR refetched, factories left empty.

  2. routerReduxSync.tsx:118 — the route-data effect's deps were [authStatus, pathname, navigate]. activeProfileId was missing, so a profile change without a pathname change didn't re-fire the effect.

Together: switching on one section and navigating to another sometimes didn't refresh — depending on timing — leaving stale or empty data.

Fix

  1. NodePickerhandleSwitchNode eagerly refetches CLN, BKPR and Factories in parallel on every profile switch, regardless of current pathname. Fire-and-forget so switch UX stays snappy, but downstream views always have data ready for the new profile.

  2. routerReduxSync — adds activeProfileId to the route-fetch effect deps + imports selectActiveProfileId. Now an active-node change re-runs the current route's data fetch against the new node.

Also drops the unused useLocation import from NodePicker (the pathname-conditional bgRefresh is gone).

Verification

CI build/eslint/test. Empirical verification on the demo wallet after deploy: switch dropdown LSP↔Client and the factories list re-populates with the correct per-node view.

…ute deps

Switching the wallet's active node via NodePicker left the factories list
empty when the user wasn't on /factories at switch time and then navigated
there afterward. The route-effect in routerReduxSync also did not re-fire
when activeProfileId changed (deps were only pathname / authStatus / navigate),
so even a fresh navigate didn't always recover.

Two defensive fixes:

1. NodePicker.handleSwitchNode now eagerly refetches ALL section data
   (CLN, BKPR, factories) on profile switch instead of only the section
   matching the current pathname. The fetches are async / fire-and-forget so
   switch UX is unaffected, but the next page the user navigates to has fresh
   data for the new profile.

2. routerReduxSync's route-fetch useEffect now includes activeProfileId in
   its deps. When the active node changes without a pathname change, the
   effect re-fires for the current pathname and refetches against the new
   node.

Repro before this PR: switch the wallet dropdown from ss-demo-lsp to
ss-demo-client (CLI factory-list on the client returns 3 factories) -- the
wallet's /factories page renders 0. After this PR: the list re-populates
on switch and on subsequent /factories navigation.

Also removes the now-unused useLocation import in NodePicker (the
pathname-conditional bgRefresh is gone).
@8144225309 8144225309 merged commit 4e28683 into main May 28, 2026
3 checks passed
@8144225309 8144225309 deleted the fix/factories-refetch-on-profile-switch branch May 28, 2026 03:29
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.

1 participant