Repository navigation
fix: defer 1.2 GB model preload until sidebar opens (closes #116) - #205
Merged
Merged
Conversation
The admin-sidebar bundle loads on every wp-admin page (intentional —
the toggle lives in the admin bar). Mounting AdminSidebar.jsx ran
initializeApp() immediately, which fired the WebGPU check, looked up
saved provider preferences, and started downloading / loading the
~1.2 GB Qwen 3 1.7B model into GPU memory.
For users who rarely open the sidebar, that's a huge unwanted cost —
both memory and the visible download progress bar in the admin bar.
Fix: React tree still mounts on every admin page (cheap, just a few
KB of components), but the WebGPU/model initialization is gated on a
`hasOpened` state that flips when the user clicks the toggle for the
first time.
Wiring:
- admin-sidebar.js dispatches a custom
`wp-agentic-admin/sidebar-opened` event when the toggle adds the
is-open class for the first time. Subsequent toggles still fire
the event (harmless — hasOpened is already true).
- AdminSidebar.jsx subscribes to the event, sets hasOpened, and a
second useEffect that depends on hasOpened runs initializeApp
when the flag flips.
- Initial state of hasOpened reads is-open from the DOM, so if some
upstream change ever makes the sidebar start open, we still
initialize on first render.
- Listener is removed once hasOpened becomes true (avoids leak).
Memory impact:
- Page load: a few KB of React + listener (no change)
- First open: full WebGPU check + cached-model auto-load (was page
load, now first open)
- Subsequent opens: no-op on the init path
No new tests — existing react/jest infra mocks model-loader and
doesn't exercise admin-sidebar.js (vanilla JS entry).
Build: clean.
Lint: clean.
Tests: 96 passing, unchanged.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ivdimova
approved these changes
May 12, 2026
ivdimova
left a comment
Collaborator
There was a problem hiding this comment.
Clean implementation. Custom event pattern keeps vanilla JS and React properly decoupled. The hasOpened initialization correctly handles the edge case where the sidebar is already open on mount. Safe to merge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The admin-sidebar bundle loads on every wp-admin page (intentional — the toggle lives in the admin bar). But mounting `AdminSidebar.jsx` immediately ran `initializeApp()`, which fired the WebGPU check, looked up saved provider preferences, and started downloading / loading the ~1.2 GB Qwen 3 1.7B model into GPU memory.
For users who rarely open the sidebar (most page loads), that's a huge unwanted cost — both memory and the visible download progress bar in the admin bar.
Net: +40 / -2 lines, 2 files touched.
Fix
React tree still mounts on every admin page (cheap — just a few KB of components), but the WebGPU/model initialization is gated on a `hasOpened` state that flips when the user clicks the toggle for the first time.
Wiring
Memory impact
Verification
Manual test plan
🤖 Generated with Claude Code