Skip to content

[AssetMapper] Fix URL pattern when importing es-module-shims #53003

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

Merged
merged 1 commit into from
Dec 20, 2023

Conversation

hashbanged
Copy link
Contributor

This fixes a JS console syntax error when importing the es-module-shims polyfills package

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #52783
License MIT

Requiring es-module-shims using AssetMapper causes a trailing export {t as default}; in the downloaded file. The recommendation in #52783 is to be explicit about checking if the package is the shims/polyfill, and, if so, to use the CSS URL pattern when building the HTTP request for the package. This PR adds a new method for handling this case, and it centralizes the logic for determining if the URL pattern should be URL_PATTERN_DIST|URL_PATTERN_DIST_CSS

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.1 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@broadcoder
Copy link

Looks like we had similar ideas: https://github.com/symfony/symfony/compare/6.4...broadcoder:symfony:fix_wrong_esm_loading_for_es_modules_shim_package_in_asset_mapper?diff=unified&w=

I wanted to leave it here, since I also started to work on it until i realised I would need to spend quite some time setting up a proper environment, but maybe you like my idea of having a list of excludes instead of a single case special handling, but very likely your solution to pass also the $entry->type is better than mine, tho :) Thanks for taking care 🙏

return self::URL_PATTERN_DIST_CSS;
}

if (str_ends_with($path, '.css') || ($type && ImportMapType::CSS === $type)) {
Copy link
Member

Choose a reason for hiding this comment

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

$type && is useless as null won't be equal to ImportMapType::CSS anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, @broadcoder! If there's a future need for more URL_PATTERN_DIST_CSS exclusions based on package name, I think that approach makes total sense. I wonder if this is really just a single edge case? @weaverryan or others? If so, it might make sense for me to drop this PR and for you to submit yours. I don't want to hijack your effort.

Sidenote: pretty sure I spent most of this PR trying to get that method name right, so props to thinking too alike. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, @stof. I removed that null check.

Copy link
Member

@weaverryan weaverryan left a comment

Choose a reason for hiding this comment

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

Minor thing - but looks good. Thank you for this!

@fabpot
Copy link
Member

fabpot commented Dec 20, 2023

Thank you @hashbanged.

@fabpot fabpot merged commit 5534989 into symfony:6.4 Dec 20, 2023
@hashbanged
Copy link
Contributor Author

Thank you, everyone, for the guidance on this.

@hashbanged hashbanged deleted the fix_52783 branch December 20, 2023 15:16
This was referenced Dec 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants