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

Skip to content

[AssetMapper] Endless importmap dependency loop due to comment #59289

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
cfoehrdes opened this issue Dec 23, 2024 · 1 comment
Closed

[AssetMapper] Endless importmap dependency loop due to comment #59289

cfoehrdes opened this issue Dec 23, 2024 · 1 comment

Comments

@cfoehrdes
Copy link

cfoehrdes commented Dec 23, 2024

Symfony version(s) affected

7.1.9

Description

I have a JS dependency (ag-grid-community version 33) which contains an exceptions message in the source code telling a developer how to import itself as module. This message is picked up by AssetMapper as an import (as mentioned in the docs it can't distinguish comments or strings from actual code). This leads to asset-mapper creating an asset for ag-grid-community with a dependency to ag-grid-community and in the end to an endless loop in Symfony\Component\AssetMapper\ImportMap\ImportMapGenerator::addImplicitEntries.

How to reproduce

Add ag-grid-community to importmap.php in version 33 and load the the page.

    'ag-grid-community' => [
        'version' => '33.0.2',
    ],

Possible Solution

I am aware that it is not possible to implement a solution distinguishing comments/string from actual syntax when checking js files for dependencies. It might make sense to add a mechanism to detect and prevent endless loops if in the dependency tree a library creates a loop by referencing itself. If circular dependencies should not be broken by asset-mapper it might make sense to allow some sort of ignore, because we have no impact on the third party library and in my opinion the error message with code snippet in their ag-grid library makes totally sense and is very helpful to their users.

Additional Context

Here is a screenshot where you can see the error message in the ag-grid source producing the import:

Screenshot 2024-12-23 at 15 10 29
@smnandre
Copy link
Member

I am aware that it is not possible to implement a solution distinguishing comments/string from actual syntax when checking js files for dependencies

It is possible... or at least it's possible in most of the cases.

I even opened a PR (twice) introducing a sequence parser for that (which would have correctly detected the import as "non code" in your specific scenario and ignored the import)

But i sincerely understand this is not the sexiest PR to review, also not everyone knows AssetMapper internals, or even uses it.

And if the code itself works, i'm not sure of the "integration" right now (a dedicated class, a function, with or without the VO..)


If circular dependencies should not be broken by asset-mapper it might make sense to allow some sort of ignore

There is a mecanism preventing circular dependencies... but none that checks if a file imports itself.

But this is easy to add and could avoid this kind of scenario :) I'll open a PR later tonight.

nicolas-grekas added a commit that referenced this issue Jan 6, 2025
…cing imports (smnandre)

This PR was merged into the 6.4 branch.

Discussion
----------

[AssetMapper] Fix JavaScript compiler creates self-referencing imports

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Issues        | Fix #59289
| License       | MIT

Ignore self-referencing imports to avoid creating circular dependencies (and infinite parsing)

Commits
-------

d6ff6c1 [AssetMapper] Fix JavaScript compiler create self-referencing imports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants