Skip to content
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

[Translator] Fix changing dump directory using AssetMapper #1904

Conversation

maelanleborgne
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
Issues Fix #1642
License MIT

The configuration node ux_translator.dump_directory wasn't correctly taken into account when using UxTranslator with AssetMapper.
This PR fixes the configuration prepend of AssetMapper to use the custom path + adds a "caution" section in the docs to remind developers to also update their importmap.php.

@carsonbot carsonbot added Bug Bug Fix Status: Needs Review Needs to be reviewed labels Jun 10, 2024
Copy link
Member

@Kocal Kocal left a comment

Choose a reason for hiding this comment

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

Good catch!

@carsonbot carsonbot added Status: Reviewed Has been reviewed by a maintainer and removed Status: Needs Review Needs to be reviewed labels Jun 10, 2024
Copy link
Contributor

@WebMamba WebMamba left a comment

Choose a reason for hiding this comment

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

Nice thanks @maelanleborgne 😁

$container->prependExtensionConfig('framework', [
'asset_mapper' => [
'paths' => [
__DIR__.'/../../assets/dist' => '@symfony/ux-translator',
'%kernel.project_dir%/var/translations' => 'var/translations',
$config['dump_directory'] => '@app/translations',
Copy link
Member

@smnandre smnandre Jun 10, 2024

Choose a reason for hiding this comment

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

Could you add a functionnal test for this ? That will prevent any future regression

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure how to test for this. I don't think I can access the config, and I can't functionally test this without requiring asset mapper in require-dev, which is not wanted. If you have any input on how I can retrieve the config from the test scope I'd be glad to hear about it :)

Copy link
Member

Choose a reason for hiding this comment

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

I shouldn't have ignored this conversation 😭

@kbond
Copy link
Member

kbond commented Jun 11, 2024

Thank you @maelanleborgne.

@kbond kbond merged commit fc8de45 into symfony:2.x Jun 11, 2024
36 checks passed
@smnandre
Copy link
Member

Well.... bad week for UX 🐞 🐞 🐞

Here is my importmap

Capture d’écran 2024-06-12 à 06 01 13

I did a composer update and...

image

To fix i just needed to replace my "var/" by "@app" links ... (and then it seems cool thanks @maelanleborgne)
Capture d’écran 2024-06-12 à 06 03 43

But we cannot do this like that//// or this will crash for everyone (with no clue/help how to fix)

So can we find something today.. or should we revert before the complaints start ? 😅

@maelanleborgne
Copy link
Contributor Author

Seems like this is caused by a small misleading info from the doc on what lines to add in importmap.php :

'@app/translations' => [
    'path' => 'var/translations/index.js',
],
'@app/translations/configuration' => [
    'path' => 'var/translations/configuration.js',
],

but importmap usually uses relative paths

'@app/translations' => [
    'path' => './var/translations/index.js',
],
'@app/translations/configuration' => [
    'path' => './var/translations/configuration.js',
],

This worked because the associated 'namespace' in asset_mapper.paths was a hardcoded var/translations.
Now with this PR changing the namespace to a more generic one, var/translations no longer resolves to %kernel.project_dir%/var/translations.
Preventing a BC here is quite tough, I see only two solutions but both are bad : updating importmap.php on the fly, or keeping a reference to the dump_dir with 'var/translations` as a namespace

$container->prependExtensionConfig('framework', [
    'asset_mapper' => [
        'paths' => [
            __DIR__.'/../../assets/dist' => '@symfony/ux-translator',
            $config['dump_directory'] => '@app/translations',
            $config['dump_directory'] => 'var/translations', // or '%kernel.project_dir%/var/translations' => 'var/translations'
        ],
    ],

Anyway, we can revert for now, I'll go fix the doc in the meantime.

kbond added a commit that referenced this pull request Jun 12, 2024
…Mapper (maelanleborgne)

This PR was merged into the 2.x branch.

Discussion
----------

[Translator] Revert Fix changing dump directory using AssetMapper

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  |no
| Issues        | #1904 (comment)
| License       | MIT

[This PR ](#1904) introduced a bug : when using 'var/translations' in the `importmap.php` file instead of a relative path, it would break the twig `importmap()` function.

~~This PR aims to rectify this regression by keeping a 'var/translations' namespace pointing to the dump_directory. If this is not accepted, the previous PR should be reverted to prevent users using 'var/translations' in there `importmap.php` to face this issue, but the documentation should still be updated to display an example using the relative path instead of a misleading namespace.~~

This PR reverts the change. A word in the doc to say that the `dump_directory` conf is not compatible with asset_mapper would be nice.

Commits
-------

e551cff Revert "Fix changing dump directory using AssetMapper"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug Fix Status: Reviewed Has been reviewed by a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Translator] Move the var/translations folder in the build_dir
6 participants