Skip to content

feat: Add lazy panel loading support#613

Open
jakduch wants to merge 19 commits into
nette:masterfrom
jakduch:feat/lazy-panel-loading
Open

feat: Add lazy panel loading support#613
jakduch wants to merge 19 commits into
nette:masterfrom
jakduch:feat/lazy-panel-loading

Conversation

@jakduch

@jakduch jakduch commented Mar 5, 2026

Copy link
Copy Markdown

Summary

Implements lazy loading for debug bar panels (resolves #530). Panels registered with lazy: true have their getPanel() deferred to a shutdown function — the tab is rendered immediately, but the panel content is stored in the session and fetched via AJAX when the user clicks or hovers over the tab.

This is useful for panels that perform expensive operations (database profiling, API call logging, heavy data analysis) — they no longer slow down the page response time.

Usage

// Normal panel (eager) — rendered during the request
Debugger::getBar()->addPanel(new MyPanel, 'my-panel');

// Lazy panel — getPanel() is called in shutdown, content served via AJAX
Debugger::getBar()->addPanel(new MyExpensivePanel, 'my-panel', lazy: true);

How it works

  1. Bar::addPanel() accepts a new lazy: bool = false parameter
  2. During renderPanels(), lazy panels skip getPanel() — only getTab() is called
  3. After the response is sent, renderLazyPanels() calls getPanel() and stores content in session via DeferredContent
  4. A new AJAX endpoint (_tracy_bar=lazy-panel.{requestId}.{panelId}) serves the panel content as JSON
  5. On the client side, bar.js detects data-tracy-lazy panels and fetches content on first interaction

Changes

  • Bar.phpaddPanel() with lazy param, renderLazyPanels() method, lazy-aware renderPanels()
  • DeferredContent.php — New lazy-panel AJAX endpoint
  • bar.jsfetchLazyContent() method, lazy-aware Panel.init()
  • bar.phtml — Lazy panels get clickable <a> tabs
  • panels.phtml — Lazy panels get data-tracy-lazy="1" attribute
  • DevelopmentStrategy.php — Calls renderLazyPanels() after render()
  • ProductionStrategy.php — Matching interface update

Demo

A demo page is included at examples/lazy-panels.php with three panels: one eager and two lazy (simulating expensive operations with usleep).

Backward compatibility

Fully backward compatible — the lazy parameter defaults to false, so existing addPanel() calls work unchanged. No changes to IBarPanel interface.

@jakduch
jakduch force-pushed the feat/lazy-panel-loading branch from 63bf239 to 44bb6fc Compare March 5, 2026 15:02
@dg
dg force-pushed the master branch 2 times, most recently from 412b7b5 to 05452cf Compare April 13, 2026 04:30
@dg
dg force-pushed the master branch 2 times, most recently from 14bf2bf to 27801ff Compare May 19, 2026 17:29
@dg
dg force-pushed the master branch 2 times, most recently from 1731e8d to efbf873 Compare July 18, 2026 02:16
Upstream master rewrote the Bar frontend (Shadow DOM) and the template
system since this branch's base, so the lazy-panel-loading feature is
re-applied on top of current master:

- Bar: addPanel(lazy:), renderLazyPanels(), lazy handling in renderPanels()
- DeferredContent: lazy-panel.<key> AJAX endpoint
- DevelopmentStrategy: renderLazyPanels() after render()
- bar.js: lazy init + fetchLazyContent() ported to the Shadow DOM frontend
- templates: clickable lazy tab + data-tracy-lazy marker; dist/ recompiled
@jakduch

jakduch commented Jul 18, 2026

Copy link
Copy Markdown
Author

@dg thanks for the 👍!

I've merged current master into the branch and resolved the conflicts. It needed a bit of rework since the Bar frontend moved to Shadow DOM and the templates were reworked, so the lazy loading is now re-applied on top of the new architecture. The PR is conflict-free and mergeable again.

A couple of questions:

  • Would you like me to keep it up to date with master going forward?
  • Is landing lazy panel loading something you'd want to include in Tracy?
  • Anything you'd like me to add or change to make it merge-ready (tests, docs, API tweaks)?

Happy to take it whatever direction works best for you.

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.

Tracy panel lazy loading

2 participants