tracy icon indicating copy to clipboard operation
tracy copied to clipboard

Not working for AJAX request during initial page load

Open repli2dev opened this issue 7 years ago • 5 comments

I am implementing Tracy in Phalcon project and I have ran into difficulties with AJAX requests. The setting is that there is page which loads multiple "snippets" from backend.

If there is an exception in the snippet two different situations occure:

  1. (During first page load) text exception is rendered instead of the "snippet"
  2. (Afterwards) normal bluescreen is triggered and showed.

Investigation (for the lack of documentation) led me to the conclusion that Tracy is initialized at the end of page, so all AJAX requests before won't be handled via bluescreen.

Can something be done with it? Can do Tracy initialization on the page start?

repli2dev avatar Feb 17 '17 11:02 repli2dev

Maybe this cdd9777066cda7be3193edc82720a75a55624a45 can help you. Call <?php Tracy\Debugger::renderLoader() ?> in head, preferably before others CSS & scripts are loaded:

<!DOCTYPE html>
<html>
<head>
	<title>...<title>
	<?php Tracy\Debugger::renderLoader() ?>
	<link rel="stylesheet" href="assets/style.css">
	<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>

dg avatar Feb 19 '17 21:02 dg

It works! However I had to delete the async as this caused to work only randomly (based on the time of loading)...

There are two options:

  1. Make it optionally (see commit diff)
  2. Remove it completely

I have done the first option and also improved documentation slightly as I was looking for this when implementing it in our non Nette project.

Diff (with txt extension because of GitHub)

Edit: noticed that static variant of method need also the param to pass it.

repli2dev avatar Feb 21 '17 09:02 repli2dev

@repli2dev thanks for diff!

dg avatar Mar 03 '17 12:03 dg

Moving Tracy's `

  1. you need to track AJAX requests during initial page load
  2. Tracy is loaded slowly, because there is some blocking or slow script or style in the page and browser is waiting

But Tracy can be blocking script too. It uses session, so it blocks until whole page is sent to browser (and session is closed). So ideal solution is to add attribute async, it perfectly solves 2). Without async it may the impression of page loading make worse.

But async doesn't solve 1). Even worse, with async you cannot count on the fact that Tracy will be loaded before event 'DOM ready' #250.

So I am not sure how to solve it.

dg avatar Mar 03 '17 15:03 dg

Yes, I see the dilema as I was feeling the same implementing the patch and that's why I implemented the turn off of async as optional.

However I would probably be OK, with previous behaviour when Tracy (by default) was loaded synchronously at the end of body... and when some would need to catch ajax request to tracy during page load (like me) then they would include the code in header and decided async themselves.

repli2dev avatar Mar 03 '17 16:03 repli2dev