Open
Conversation
Panels registered with `lazy: true` have their getPanel() deferred to a shutdown function. The tab renders immediately, but panel content is stored in session and fetched via AJAX on first interaction. This avoids expensive panel rendering blocking the page response. Usage: Debugger::getBar()->addPanel($panel, 'id', lazy: true);
63bf239 to
44bb6fc
Compare
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
Implements lazy loading for debug bar panels (resolves #530). Panels registered with
lazy: truehave theirgetPanel()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
How it works
Bar::addPanel()accepts a newlazy: bool = falseparameterrenderPanels(), lazy panels skipgetPanel()— onlygetTab()is calledrenderLazyPanels()callsgetPanel()and stores content in session viaDeferredContent_tracy_bar=lazy-panel.{requestId}.{panelId}) serves the panel content as JSONbar.jsdetectsdata-tracy-lazypanels and fetches content on first interactionChanges
Bar.php—addPanel()withlazyparam,renderLazyPanels()method, lazy-awarerenderPanels()DeferredContent.php— Newlazy-panelAJAX endpointbar.js—fetchLazyContent()method, lazy-awarePanel.init()bar.phtml— Lazy panels get clickable<a>tabspanels.phtml— Lazy panels getdata-tracy-lazy="1"attributeDevelopmentStrategy.php— CallsrenderLazyPanels()afterrender()ProductionStrategy.php— Matching interface updateDemo
A demo page is included at
examples/lazy-panels.phpwith three panels: one eager and two lazy (simulating expensive operations withusleep).Backward compatibility
Fully backward compatible — the
lazyparameter defaults tofalse, so existingaddPanel()calls work unchanged. No changes toIBarPanelinterface.