Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Sign up
Appearance settings

[WebProfilerBundle] Add missing Javascript function to prevent undefined function#48037

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

Closed
PhilETaylor wants to merge5 commits intosymfony:5.4fromPhilETaylor:patch-9

Conversation

@PhilETaylor
Copy link
Contributor

QA
Branch?5.4+
Bug fix?yes
New feature?no
Deprecations?no
LicenseMIT

So.... To replicate create a demo app with Symfony 5.4, 6.1, 6.2....

composer create-project symfony/symfony-demo mySymfony54 1.8.0cd mySymfony54symfony serve# Visit http://127.0.0.1:8000/en/blog/ to confirm its working# Edit BlogController.php and throw an \Exception('test') in the index function

The result is a Javascript error in the console log:

TypeError: Sfjs.createFilters is not a function. (In 'Sfjs.createFilters()', 'Sfjs.createFilters' is undefined)

Screenshot 2022-10-28 at 23 32 20

Now, Javascript in the profiler is loaded from two places (and each of these files has a header alerting you to that fact and that changes in one should be considered for the other too)

Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig (has no Sfjs.createFilters function)Symfony/Component/ErrorHandler/Resources/assets/js/exception.js (Has a Sfjs.createFilters function)

Both files will only run their definition of theSfjs if thetypeof Sfjs === 'undefined' is true... so if one loads before the other then the latter will not redefine theSfjs

However, what is happening is that thebase_js.html.twig is defining theSfjs object beforeexception.js gets a chance - and because theSfjs.createFilters function is not inbase_js.html.twig its not defined and so the error message tells us that.

This PR duplicates the method into thebase_js.html.twig version of theSfjs object so that it can be called from the code (at the bottom of)exception.js and thus the console.log error message is now gone.

The code provided in this PR is not my code, its direct copy of the code fromexception.js

@MatTheCat
Copy link
Contributor

The issue rather comes from the factbase_js.html.twig redefinesSfjs ifSfjs.loadToolbar is undefined.

So ifexception.js runs first it will define a version ofSfjs withcreateFilters and noloadToolbar. Problem is, it callscreateFilters onDOMContentLoaded. So whenbase_js.html.twig kicks in, it redefinesSfjs withloadToolbar and nocreateFilters. ThenDOMContentLoaded is triggered and it tries to callcreateFilters.

I don’t even know why there are two flavors ofSfjs?

@PhilETaylor
Copy link
ContributorAuthor

lol you literally just paraphrased what I had already said :)

I don’t even know why there are two flavors of Sfjs?

I guess you could show exceptions withcomponent/ErrorHandler without theWebProfilerBundle being installed, thusexception.js would be the only code running.

@MatTheCat
Copy link
Contributor

Quite the opposite in fact: you’re sayingbase_js.html.twig is definingSfjs beforeexception.js but it’s wrong because in that casecreateFilters would not be called and there would be no error.

GivencreateFilters targets[data-filters] and the only one exists in the translation collector, I’m not even sure it serves any purpose.

@PhilETaylor
Copy link
ContributorAuthor

PhilETaylor commentedOct 29, 2022
edited
Loading

I’m not even sure it serves any purpose.

I did think that, but I like to assume everything in Symfony has a reason to be there and that the code it mostly bug free. Maybe. I assume too much :)

So you would propose to remove calls to this function in theexception.js? In fact I think that's the better solution because<script>Sfjs.createFilters();</script> is called intranslation.html.twig itself.

but it’s wrong because in that case createFilters would not be called and there would be no error.

The calls to the function are outside the "if undefined" block, and so they do get called.

@PhilETaylor
Copy link
ContributorAuthor

So you would propose to remove calls to this function in the exception.js? In fact I think that's the better solution because <script>Sfjs.createFilters();</script> is called in translation.html.twig itself.

PR updated now to just that change.

@MatTheCat
Copy link
Contributor

MatTheCat commentedOct 29, 2022
edited
Loading

IfcreateFilters is only called when it’s not defined it can be removed with all of its invocations and the related markup.

@MatTheCat
Copy link
Contributor

I think every occurrence oftable-filters ortable-filter attributes in HTML or CSS can be removed 🤔

Maybe you could change the PR’s title too!

@nicolas-grekas
Copy link
Member

Friendly ping@PhilETaylor

@PhilETaylor
Copy link
ContributorAuthor

Friendly ping@PhilETaylor

Thanks. Yup I know I suck :) I have this one and the Doctrine profiler PR to revisit, it's still on my plate to do both. Sorry for the delay.

@nicolas-grekas
Copy link
Member

Closing as this stalled. Please resubmit when you can. Or maybe@MatTheCat if you're up to?

@MatTheCat
Copy link
Contributor

I opened#50108 because we missed the big picture in this PR 😅

fabpot added a commit that referenced this pull requestMay 5, 2023
…JavaScript (MatTheCat)This PR was merged into the 5.4 branch.Discussion----------[ErrorHandler] Prevent conflicts with WebProfilerBundle’s JavaScript| Q             | A| ------------- | ---| Branch?       | 5.4| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Tickets       |Fix#50108| License       | MIT| Doc PR        | N/AErrorHandler’s `exception.js` and WebProfilerBundle’s `base_js.html.twig` both expose a global `Sfjs` variable, which create conflicts (see linked issue e.g.).As the exception page- does not make use of `Sfjs`- is not extensibleI updated `exception.js` to not create any global scope variable. I also removed `DOMContentLoaded` listeners as the script is run inline at the end of the document.This PR stems from#48037.Hiding whitespaces will produce a much more readable diff.Commits-------e331b28 Do not expose `Sfjs` as it is unused and conflicts with WebProfilerBundle’s
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@ycerutoycerutoAwaiting requested review from ycerutoyceruto is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

5.4

Development

Successfully merging this pull request may close these issues.

4 participants

@PhilETaylor@MatTheCat@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp