Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[BUG][Profiler][Timeline] JS error with custom events/sections #30745

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

Closed
ovrflo opened this issue Mar 28, 2019 · 4 comments · Fixed by #30973
Closed

[BUG][Profiler][Timeline] JS error with custom events/sections #30745

ovrflo opened this issue Mar 28, 2019 · 4 comments · Fixed by #30973

Comments

@ovrflo
Copy link
Contributor

ovrflo commented Mar 28, 2019

Symfony version(s) affected: 4.3-DEV

Description

Looks like #30450 broke the Timeline panel in profiler with sections other than standard symfony ones. I have a custom caching bundle that uses the Stopwatch to measure (and also display in profiler) cache call duration. When the Timeline page loads, it throws JS error because the category ovrflo_cache does not exist (as it is not one of the hardcoded ones).

How to reproduce
This controller will reproduce the problem:

    public function index(Stopwatch $stopwatch)
    {
        $stopwatch->start('some_name', 'some_category');
        sleep(1);
        $stopwatch->stop('some_name');

        return new Response('</body>');
    }

Click on the debug toolbar, go to Timeline, open Dev Tools and you'll see the error.

Possible Solution
I fiddled with the JS in @WebProfiler/Collector/time.js and I got it to work. I am ready to submit a PR with my code, but I'm not proud of it. I'm a bit rusty with JS/ES6. If you want me to submit a PR with my fix, let me know. If someone else wants to take a stab at it, the issues I found are with 2 calls

  • Legend.add cannot find the category in this.categories
  • Legend.getClassname cannot find the category in this.classnames
    My fix detects those undefined values and adds the category in both places with default values.

Edit: I just pushed my fix if anyone wants to take a look at it: ovrflo@17be20a

This probably affects any third party bundle that uses the Stopwatch. We should fix this ASAP.

@ovrflo
Copy link
Contributor Author

ovrflo commented Mar 28, 2019

Found another bug in @WebProfiler/Collector/time.html.twig.
It tries to transform the events in the profile into a format usable by JavaScript. When doing that, it uses {{ "%F"|format(someFloatValue) }}.

Randomly, my page had event.starttime = -0.1, which caused that sprintf to print -0.1. That would be fine (kinda) if it wouldn't be printed with some unicode dash (starttime: \u002D0.100000,) causing the page to throw Uncaught SyntaxError: Invalid or unexpected token.

I'm not sure how to fix this. I would probably get rid of those sprintf calls, but that would mean assuming that I really get floats/integers. If something else gets there it may fail.

Another solution may be to just move that code to the Collector, handle it properly in PHP (will all the needed casts) and then dump it in Twig with |json_encode|raw. It's a bit more work, but I would go with this. Should I open a separate issue for this one ? And/or a PR ?

Please advise. Thanks !

@curry684
Copy link
Contributor

curry684 commented Apr 7, 2019

Picking this up at EUFOSSA.

Status: reviewed

@curry684
Copy link
Contributor

curry684 commented Apr 7, 2019

I fixed the first issue in #30973

The second issue just sounds like GIGO to me - you're "corrupting" the data to something it shouldn't ever contain. Not something I really think we can make the profiler resistant to.

@ovrflo
Copy link
Contributor Author

ovrflo commented Apr 8, 2019

@curry684 thank you very much for your fix :)
Also, you're probably right on the second issue. It also seems to reproduce randomly. I actually don't think I saw it happen after reporting it here. If I manage to reproduce it and get to the bottom of it, I'll open a new issue.

Thanks again !

@fabpot fabpot closed this as completed Apr 8, 2019
fabpot added a commit that referenced this issue Apr 8, 2019
…atch categories (curry684)

This PR was squashed before being merged into the 4.3-dev branch (closes #30973).

Discussion
----------

[WebProfiler] Fix Javascript error when using custom stopwatch categories

Fixes #30745

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #30745
| License       | MIT

Made the getter do lazy creation so it can dynamically adapt to whatever it's given.

Commits
-------

e991472 [WebProfiler] Fix Javascript error when using custom stopwatch categories
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants