magpie icon indicating copy to clipboard operation
magpie copied to clipboard

Plugin pages reappear in the sidebar after every update although Settings › General › Sidebar pages still lists them as hidden

Open Beyfish opened this issue 2 weeks ago • 6 comments

Summary

Pages hidden in Settings › General › Sidebar pages come back in the sidebar after every magpie update for third-party (plugin) pages only — while the setting keeps showing them as hidden. Built-in pages (Agents, Routing, …) survive the update correctly; only plugin tabs reappear.

Root cause

internal/gui/assets/app.js filters the sidebar (navHides(), around line 23483):

function navHides() {
  if (mode !== "window") return;
  window.navArrange ? navArrange() : navList("Order").length && import("./navorder.js").then(navHides, () => {});
  for (const b of $("#nav").querySelectorAll("button[data-view]")) b.hidden = ... || navMine().includes(b.dataset.view);
}

Its only callers are start.js (once, at boot, before plugin tabs exist), navpages.js after a save, setGatewayMode() and applyFeatures() (app.js). The plugin tabs, however, are built asynchronously in pluginpages.js load() (245-318): it await api("plugin-pages") (248), creates and appends every tab (306), and then only calls navSubs() (309) — never navHides() / navArrange(). So after a restart/update the new tabs are created with hidden === false and nothing re-applies the stored magpie.navHidden list. The setting itself is drawn from the same stored list (navpages.js:120 const mine = navMine()), so it still says "hidden" — exactly the reported contradiction.

A secondary factor: plugin page keys are not stable. internal/gui/pluginpage.go:133-155 (windowParts) derives the key from plugin.ShortName(PackageName(spec)) and de-duplicates repeats by appending -2, -3, … in plugins.json order (pluginpage.go:152). A reinstall/update that changes that order (or adds/removes a duplicate package) renames the key, so the stored entry no longer matches and the tab shows even if the filter did run.

Repro

  1. Hide one or more plugin pages in Settings › General › Sidebar pages.
  2. Update magpie (or restart into a build whose plugins.json order changed).
  3. The plugin tabs are back in the sidebar; the menu still lists them as hidden.
  4. Uncheck and re-check any of them — they disappear again (a write is what applies the filter).

Suggested fix

  • In pluginpages.js load(), after the navSubs() call, also call navHides() (it already runs navArrange()), and refresh the row with window.renderNavPages?.(). That puts freshly created plugin tabs through the same filter as built-in pages.
  • Optionally, derive the plugin page key from something stable instead of plugins.json order (package name alone with a deterministic suffix), or re-map orphaned magpie.navHidden entries when a key disappears, so an update can never leave dead entries behind.

Environment

  • magpie 0.1.4594 (Windows 11 x64); %USERPROFILE%\.config\magpie\plugins.json has 38 entries; two packages (opencode-catpaw-auth, opencode-orcaterm-auth) appear twice each, once as an installed node_modules path and once as …@latest, so their generated keys collide today and whichever row comes second gets the …-2 suffix. Any reinstall or update that re-orders those rows renames the page.
  • Code read on main @ b9dc1d0b (v0.1.4595).
  • Introduced by 22f2759d7 (closing #5685); ordering by b010fba05.

Investigation only — no local fix applied, and no duplicate of #5685: that one added the setting, this is the filter not being re-run for tabs created later.

Beyfish avatar Nov 20 '26 10:11 Beyfish

I have a fix ready on a fork branch (9997313c, based on main at 5f952c8): https://github.com/yetone/magpie/compare/main...eisen0419:magpie:fix/7335-plugin-pages-nav-hides

Cause:

  1. Plugin sidebar tabs are created asynchronously in pluginpages.js load() after start.js has already run navHides(), so tabs hidden in magpie.navHidden reappeared on every restart/update (and custom sidebar order was not re-applied once they appeared).
  2. In internal/gui/pluginpage.go, duplicate copies of the same package received -2/-3 suffixes in plugins.json iteration order, so reordering plugins.json renamed their page keys.

Fix:

  • Added afterPages in pluginnav.js (keeping index.html core script budget down by 98 bytes: 1,275,224 -> 1,275,126) to run navHides, navSubs, and renderNavPages once plugin tabs load, avoid restoring a hidden plugin page from magpie.lastView while still allowing explicit ?view=, and preserve replaces positioning in navArrange.
  • Assigned duplicate plugin page keys (-2, -3, ...) deterministically in spec order rather than plugins.json order (single-install plugins keep their exact existing plugin-<shortname> key; first-enabled built-in replaces precedence stays unchanged).

Verification (temp HOME, go1.27.1):

  • gofmt -l clean; go vet -tags nogui ./... clean.
  • go test -count=1 -tags nogui -run 'TestPluginPageKeysStayPut|TestPluginPageReplacesFirstWins|TestPluginPanelsServedShutIn|TestPluginPageServedShutIn|TestCoreScriptBudget' ./internal/gui: ok.
  • Playwright GUI tests (plugin-page-nav-hidden.test.cjs 4/4, nav-pages-hidden.test.cjs + nav-pages-order.test.cjs 12/12): all green on both Chromium and WebKit.

eisen0419 avatar Nov 20 '26 14:11 eisen0419

Thank you for preparing the fix and the focused tests. I checked the comparison: applying hidden/subscription state after async page loading addresses the timing described in my report. I could not find an upstream PR linked to #7335 yet; could you open one from this branch so the maintainer can review and release it?

One compatibility case is worth covering in that PR: the first upgrade from the old ordinal duplicate keys. With two identical base keys and old spec order [z, a], the old algorithm assigns the base key to z and -2 to a; sorting specs assigns the base to a instead. An existing navHidden choice may therefore hide the other duplicate on the first upgrade. Please document/handle that transition or include a regression starting from the old key assignment, rather than only checking reorder stability under the new algorithm.

I have not installed this fork or treated the reported Chromium/WebKit results as a Windows WebView2 runtime pass. After an official build is available, the relevant Windows check is: hidden plugin tabs stay hidden across upgrade/restart, an implicitly restored hidden lastView falls back safely, an explicit ?view= link remains usable, and custom order/replacement placement does not drift.

Beyfish avatar Nov 20 '26 18:11 Beyfish

@Beyfish Thanks for reviewing the compare diff.

  1. Why there is no PR: yetone/magpie restricts PR creation to collaborators (see docs/contributors.md), so external fixes are shared via fork branches on the issue for maintainers to review and pull.
  2. First-upgrade transition for duplicate colliding short-names: Good catch — single-install plugins keep their exact plugin-<shortname> key unchanged, and the one-time key swap only applies if two enabled plugins collide on the same base key and happened to be ordered [z, a] in plugins.json before upgrade. Because any order-independent deterministic key assignment cannot simultaneously preserve arbitrary prior plugins.json order without storing a separate persisted key map, sorting colliding specs does a one-time canonicalization on that first upgrade and prevents further drift on reorders afterward. Happy to drop the duplicate-key sorting if maintainers prefer keeping the minimal async-afterPages fix only, or to add a persisted map if they'd rather migrate [z, a] duplicates seamlessly.

eisen0419 avatar Nov 20 '26 19:11 eisen0419

Thanks for clarifying — I missed docs/contributors.md when asking for a PR. I have checked it now: this repository accepts external fixes via issue-linked fork branches for maintainers to review/pull. I will not ask you to bypass the collaborator restriction.

For my original sidebar report, I would prefer the minimal async afterPages fix that preserves existing page keys, with duplicate-key identity/canonicalization handled as a separate change. Your explanation of the one-time [z, a] transition is clear; it should not be described as preserving every existing hide choice. This is a reporter preference, not a maintainer decision or permission to add a new persisted-key scheme.

@yetone / maintainers: could you review and pull the contributed fix branch through the documented workflow, and choose whether to take the minimal timing fix first or include the duplicate-key behavior with an explicit migration decision? Please retain the contributor's authorship/credit as the policy specifies.

I have not installed the fork or claimed Windows WebView2 verification. After an official build is available, I can check the original persisted-hidden-state behavior and the stated navigation compatibility cases. No additional private session or account material is needed for that.

Beyfish avatar Nov 20 '26 19:11 Beyfish

Fixed in d0d8e02c2 (v0.1.5015): pluginpages.js's load now runs navHides, navSubs and Settings' count each time it draws the plugin tabs, and a kept lastView that is a hidden plugin page is not reopened (?view= still opens it). Also taken from eisen0419's 9997313c, with credit: navArrange keeps a plugin page in a built-in's place beside it when the order is applied later. The duplicate-key change in pluginpage.go is not in this commit, as you asked. I'm leaving this open until you confirm it holds after an update.

yetone avatar Nov 28 '26 10:11 yetone

Confirmed on my end — verified on v0.1.5276: I disabled a plugin page in Settings › General › Sidebar pages, restarted, and it stayed hidden instead of reappearing in the sidebar. The duplicate-key change in pluginpage.go is not needed on my side, exactly as requested.

Thanks, and credit given for 9997313c. I'm closing this as fixed.

Beyfish avatar Dec 01 '26 10:12 Beyfish