Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
WDT: Only load "Sfjs" if it is not present already#41168
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Merged
Uh oh!
There was an error while loading.Please reload this page.
Conversation
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
Plus, avoid loading the toolbar if it is no longer on the page
stof approved these changesMay 10, 2021
chalasr approved these changesMay 10, 2021
fabpot approved these changesMay 11, 2021
Member
fabpot commentedMay 11, 2021
Thank you@weaverryan. |
This was referencedMay 12, 2021
Merged
Merged
Merged
nicolas-grekas added a commit that referenced this pull requestMay 21, 2021
…d also loading base_js Sfjs if needed (weaverryan)This PR was merged into the 4.4 branch.Discussion----------[WebProfilerBundle] Wrapping exception js in Sfjs check and also loading base_js Sfjs if needed| Q | A| ------------- | ---| Branch? | 4.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Tickets |Fix#41305| License | MIT| Doc PR | Not neededThis bug was introduced in#41168.Best viewed with:https://github.com/symfony/symfony/pull/41346/files?w=1 - we could also remove the new indentation in `exception.js`.In that PR, we innocently don't reload `Sfjs` if it doesn't exist. However, on an error page, that template ALSO adds an `Sfjs`, and that `Sfjs` is *smaller* - containing only a subset of the `Sfjs` functions. This is tricky, but this PR fixes it.Here are the various situations:1) I hit an exception page. The `Sfjs` from `exception.js` is loaded first. This adds the smaller `Sfjs`. Then the `base_js.html.twig` version is hit. Because `Sfjs` is missing the `loadToolbar()` method, that code DOES run again to reinitialize it.2) I am on a normal page, then travel to an exception page with Turbo. In this case, the original `Sfjs` from `base_js.html.twig` was processed. Then, on the exception page, the `Sfjs` from `exception.js` is ignored, as is the 2nd execution of `base_js.html.twig`.Overall, the JS could use some work for supporting things like Turbo (e.g. `DOMContentLoaded` doesn't work with Turbo, so the exception page JS is broken). But I wanted to focus on fixing the bug in this PR.As a reminder,#41168 (avoiding overriding `Sfjs`) was done to help with the AJAX toolbar and Turbo - it's explained in point (1) on#41168.Cheers!Commits-------5fa42f1 Wrapping exception js in Sfjs check and also loading base_js Sfjs if needed
Sign up for freeto 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.
Hi!
Playing with Turbo, I noticed two small issues with the WDT:
When you click a link (which Turbo loads via AJAX), the new toolbar would correctly load, but its "AJAX tab" would be missing/empty. At first, that seems.. at least... "correct enough". After all, wedid just load a new web debug toolbar. However, this can be avoided by simplynot redefining the
Sfjsvariable: if it already exists, just use it. And this is the intention of that object, I believe: for it to be loadedonce, and then reused over and over again via itsloadToolbar()method.Additionally, I was experimenting with some crazy prefetch + Turbo functionality. It works, but caused one minor issue with the web debug toolbar. The flow is this:
A) A prefetch request is made to pre-cache a URL in Turbo.
B) When that links is actually clicked, the cached version from (A) is used as the "Preview". It's HTML calls
Sfjs.loadToolbar().C) At the same moment as (B), another AJAX request is made to the same URL from (A) to get the full, fresh page (in case it's out of date).
D) When (C) finishes, it will have its own
Sfjs.loadToolbar()call.The problem is that the AJAX request for the first web debug toolbar (from B) sometimes finishesafter the AJAX call made by Turbo for (C). The result is that the first web debug toolbar tries to activate itself... but it's already gone from the page.
I realize this is a... kind of crazy scenario, but I think the fix is legit: if, for any reason, the web debug toolbar element is not on the page, we should not try to initialize it. It results in:
To Test
JUST to be on the safe side, I prepared a symfony-demo app with Turbo installed, and using these changes. You can try it here -https://github.com/weaverryan/symfony-demo/tree/turbo - the README is updated to quickly get it running (no need to even run yarn, the JavaScript files are committed).
Thanks!