Skip to content

fix: lazy-load frontend panel assets on first toggle - #93

Merged
jackgranatowski merged 3 commits into
mainfrom
claude/frontend-panel-visibility-qnsbmh
Jun 29, 2026
Merged

fix: lazy-load frontend panel assets on first toggle#93
jackgranatowski merged 3 commits into
mainfrom
claude/frontend-panel-visibility-qnsbmh

Conversation

@jackgranatowski

@jackgranatowski jackgranatowski commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Improves the frontend panel initialization by deferring asset loading until the user first toggles the design panel. When the panel assets haven't been loaded yet, clicking the "/ Design" button now navigates to the current URL with a ?slashed-frontend-panel query parameter, which triggers asset injection on page load. Once loaded, subsequent toggles use a custom DOM event to avoid page reloads.

This reduces initial page load overhead by only loading panel assets when needed, while maintaining a seamless UX after the first toggle.

Type

  • fix
  • feat
  • docs
  • chore / tooling

Checklist

  • Conventional Commit messages (feat:, fix:, docs:, …)
  • npm test passes
  • npm run lint passes (stylelint + php -l)
  • npm run verify passes (version metadata in sync)
  • Generated artifacts not hand-edited (dist/, data/inventory.json, data/classes-hints.json come from update-framework / build:data)
  • CHANGELOG.md updated under ## [Unreleased] (for user-facing changes)
  • Built SPA assets committed if editor-app/admin-app source changed

Notes

The logic now checks for the presence of the slashed-frontend-panel query parameter to determine whether assets are already loaded:

  • First toggle: Button href navigates to same URL with query param appended; no onclick handler
  • Subsequent toggles: Button href is # with custom event dispatcher in onclick handler

This maintains backward compatibility while optimizing initial page load performance.

https://claude.ai/code/session_01DehHEfopxfkGpyN3tRmys8

Summary by CodeRabbit

  • New Features
    • The “/ Design” admin-bar control now supports two behaviors: it can open the front-end panel directly when available, or reload the page with the panel enabled when needed.
    • When the panel is already loaded, the control toggles the overlay instantly without a page refresh.

claude added 2 commits June 29, 2026 08:59
…n assets not loaded

The button was dispatching a custom DOM event that had no listener because
the overlay JS is only enqueued when ?slashed-frontend-panel is in the URL.
Now the button navigates to the current URL with the query param when the
panel is inactive, and falls back to the toggle event when it is already
loaded.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DehHEfopxfkGpyN3tRmys8
The AppOverlay source had the save button repositioned before undo/redo in
commit b071a99, but the compiled assets were never rebuilt — the deployed
app.js still reflected the old button order. Rebuilding now includes the
corrected header layout and all subsequent source changes (reset-all
confirmation dialog, page-squeeze margin effect, aria-label on save button).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DehHEfopxfkGpyN3tRmys8
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@jackgranatowski, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 55 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ccd74ca1-ef9f-4402-8de2-02d62bd10608

📥 Commits

Reviewing files that changed from the base of the PR and between c716122 and ea2c1eb.

📒 Files selected for processing (3)
  • SLASHED-for-WP/admin-app/src/plugin-main.ts
  • SLASHED-for-WP/assets/admin-app/app.js
  • SLASHED-for-WP/includes/class-frontend-configurator.php
📝 Walkthrough

Walkthrough

The add_admin_bar_node method in class-frontend-configurator.php is updated to conditionally set the admin-bar Design node's href and onclick based on whether $_GET['slashed-frontend-panel'] is present, toggling via a custom DOM event when active or navigating with the query param when inactive.

Changes

Admin-bar Design node conditional toggle

Layer / File(s) Summary
Conditional onclick/href and docblock
SLASHED-for-WP/includes/class-frontend-configurator.php
Docblock expanded to describe two activation modes. add_admin_bar_node reads $_GET['slashed-frontend-panel'] and sets href="#" with a CustomEvent("slashed:toggle-overlay") dispatch when active, or sets href via add_query_arg with no onclick when inactive. A PHPCS ignore is placed on the $_GET access.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • codeslash-dev/SLASHED-Plugins#86: Both PRs modify add_admin_bar_node in class-frontend-configurator.php to control the Design admin-bar node behavior and frontend overlay triggering.
  • codeslash-dev/SLASHED-Plugins#91: Both PRs gate frontend overlay behavior on the slashed-frontend-panel query parameter in class-frontend-configurator.php.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: lazy-loading frontend panel assets on first toggle.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/frontend-panel-visibility-qnsbmh

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Lazy-load frontend design panel assets on first toggle
🐞 Bug fix ✨ Enhancement 🕐 20-40 Minutes

Grey Divider

Description

• Make the “/ Design” admin-bar button load overlay assets only on first use.
• Use URL query param for first activation; use a DOM event for subsequent toggles.
• Rebuild bundled admin-app assets to include latest overlay UI/layout changes.
Diagram

graph TD
  U(["Admin user"]) --> B["/ Design button"] --> D{"Panel param present?"}
  D -->|"No"| N["Navigate w/ param"] --> W["Frontend Configurator PHP"] --> A[("admin-app bundle")] --> O["Overlay panel"]
  D -->|"Yes"| E["Dispatch toggle event"] --> O
  subgraph Legend
    direction LR
    _u(["User"]) ~~~ _p["Process"] ~~~ _d{"Decision"} ~~~ _a[("Assets")]
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Always enqueue a tiny bootstrap script
  • ➕ No full page reload needed on first toggle
  • ➕ Can dynamically inject JS/CSS when user requests panel
  • ➖ Adds additional script to every frontend page for capable users
  • ➖ More complexity: script-loader + race conditions + error handling
2. Use wp_enqueue_scripts conditional on capability only
  • ➕ Simplest behavior; no query param or navigation logic
  • ➖ Always pays asset cost even when panel never used
  • ➖ Worse TTFB/LCP on frontend for admins

Recommendation: Current approach is a good tradeoff: it keeps default frontend loads lean by gating enqueuing behind ?slashed-frontend-panel, while still providing a seamless post-load UX via event-based toggling. A bootstrap loader could avoid the first reload, but would increase complexity and still add baseline overhead to all eligible pages.

Files changed (3) +89 / -63

Bug fix (1) +18 / -3
class-frontend-configurator.phpMake admin-bar toggle lazy-load overlay assets via query param +18/-3

Make admin-bar toggle lazy-load overlay assets via query param

• Updates the “/ Design” admin-bar node to detect whether ?slashed-frontend-panel is present. If not present, the button navigates to the same URL with the query param to trigger asset enqueueing on load; if present, it uses a CustomEvent (slashed:toggle-overlay) to toggle without reloading.

SLASHED-for-WP/includes/class-frontend-configurator.php

Other (2) +71 / -60
app.jsRebuild admin-app bundle (overlay UI + toggle behavior support) +70/-59

Rebuild admin-app bundle (overlay UI + toggle behavior support)

• Updates the compiled admin-app JavaScript bundle to reflect the latest overlay application source changes. This includes the rebuilt overlay UI/layout adjustments mentioned in the commit message and ensures the runtime behavior aligns with the updated frontend activation flow.

SLASHED-for-WP/assets/admin-app/app.js

app.cssRebuild admin-app CSS bundle +1/-1

Rebuild admin-app CSS bundle

• Updates the compiled admin-app CSS bundle to stay in sync with the rebuilt JS/app sources. This is a generated artifact change expected from the asset rebuild.

SLASHED-for-WP/assets/admin-app/app.css

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@SLASHED-for-WP/includes/class-frontend-configurator.php`:
- Around line 117-123: The readiness check in the frontend configurator is using
the query parameter too early, which makes the admin-bar toggle link become a
no-op before the overlay listener is mounted. Update the logic in the frontend
configurator branch that sets the link target so it keeps a real navigation
fallback until the frontend is actually ready, or only returns false when a
client-side readiness flag indicates the `slashed:toggle-overlay` handler is
mounted. Use the existing frontend configurator path and the admin-bar link
setup that currently assigns `$href` and `$onclick` to locate the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: af27efc3-108c-4ab8-9163-b95dc183771e

📥 Commits

Reviewing files that changed from the base of the PR and between f039b04 and c716122.

📒 Files selected for processing (3)
  • SLASHED-for-WP/assets/admin-app/app.css
  • SLASHED-for-WP/assets/admin-app/app.js
  • SLASHED-for-WP/includes/class-frontend-configurator.php

Comment thread SLASHED-for-WP/includes/class-frontend-configurator.php
…allback

The admin-bar button was setting href="#" and return false as soon as
?slashed-frontend-panel was in the URL, but plugin-main.ts defers mount()
until the overlay CSS loads (up to 5 s). Any click during that window
dispatched slashed:toggle-overlay to no listener and blocked navigation —
a silent no-op.

Fix: plugin-main.ts now sets data-slashed-ready on the mount container
after mount() succeeds. The PHP onclick checks for this attribute and only
dispatches the event + prevents default when it is present. When absent,
default navigation follows the real URL (current page with the query
param), triggering a reload that lands on a fully-mounted panel.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DehHEfopxfkGpyN3tRmys8
@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Qodo Logo

@jackgranatowski
jackgranatowski merged commit a01b91d into main Jun 29, 2026
9 checks passed
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.

2 participants