Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[WebProfilerBundle] Live duration of AJAX request #26668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2018

Conversation

ostrolucky
Copy link
Contributor

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #26645
License MIT
Doc PR -

This will spit out current calculated AJAX request duration, before it finishes. Solves my DX issue about not knowing if request is still in progress.

peek 2018-03-25 15-07

@linaori
Copy link
Contributor

linaori commented Mar 26, 2018

This looks pretty useful!

Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

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

I like this! Before merging, let's wait a bit for reviews from JavaScript experts ... although this already looks as correct as it can be.

@@ -158,6 +158,7 @@
durationCell.className = 'sf-ajax-request-duration';
durationCell.textContent = 'n/a';
row.appendChild(durationCell);
request.updateDuration = setInterval(request.updateDuration, 100, durationCell);
Copy link
Member

Choose a reason for hiding this comment

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

using request.updateDuration to store both the callback and the timer identifier after that looks wrong to me. It will make it much easier to introduce bugs by mistake in the future.

@@ -264,6 +267,9 @@
url: url,
method: method,
type: 'fetch',
updateDuration: function(element) {
Copy link
Member

Choose a reason for hiding this comment

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

you need to do the same in the code handling XMLHttpRequest. This code does it only for fetch (which will break stuff as startAjaxRequest is used by both)

@@ -264,6 +267,9 @@
url: url,
method: method,
type: 'fetch',
updateDuration: function(element) {
element.textContent = (new Date() - stackElement.start) + 'ms';
Copy link
Member

Choose a reason for hiding this comment

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

instead of using a closure to keep a reference to stackElement.start here (which forces you to create the callback in 2 places to make it available for startAjaxRequest), you could instead also pass the start time as an argument in the setInterval call, as you do for the DOM node (and then, you can define the function only once as a sibling of startAjaxRequest and finishAjaxRequest, and reuse it for all requests).

This would also solve the re-purposing of the field.

@ostrolucky
Copy link
Contributor Author

Ok how about this? Even less lines and no need to pass arguments to closure \o/

@ostrolucky ostrolucky force-pushed the feature-ajax-live-duration branch from f303e5b to 7696bf9 Compare March 26, 2018 21:59
@@ -159,6 +159,10 @@
durationCell.textContent = 'n/a';
row.appendChild(durationCell);

request.liveDurationHandle = setInterval(function() {
durationCell.textContent = (new Date() - request.start) + 'ms';
}, 100);
Copy link
Member

Choose a reason for hiding this comment

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

Looks like there is an indentation issue here (tabs?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

indeed

@stof
Copy link
Member

stof commented Mar 27, 2018

@ostrolucky can you rebase your branch to fix conflicts ?

@ostrolucky ostrolucky force-pushed the feature-ajax-live-duration branch from 1bfee88 to eb6974d Compare March 27, 2018 09:03
@ostrolucky
Copy link
Contributor Author

sure, done!

@fabpot
Copy link
Member

fabpot commented Mar 27, 2018

Thank you @ostrolucky.

@fabpot fabpot merged commit eb6974d into symfony:master Mar 27, 2018
fabpot added a commit that referenced this pull request Mar 27, 2018
…rolucky)

This PR was merged into the 4.1-dev branch.

Discussion
----------

[WebProfilerBundle] Live duration of AJAX request

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #26645
| License       | MIT
| Doc PR        | -

This will spit out current calculated AJAX request duration, before it finishes. Solves my DX issue about not knowing if request is still in progress.

![peek 2018-03-25 15-07](https://user-images.githubusercontent.com/496233/37875667-f45376a8-3042-11e8-87e5-24416b8ba670.gif)

Commits
-------

eb6974d [WebProfilerBundle] Live duration of AJAX request
@fabpot fabpot mentioned this pull request May 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.