Skip to content

[AssetMapper] avoid caching MappedAsset inside JavaScript Import #52523

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

Conversation

weaverryan
Copy link
Member

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues None
License MIT

Hi!

Subtle bug. In dev, we cache the MappedAsset objects. Before this PR, MappedAsset->javascriptImports[0]->asset was also a MappedAsset object.

Suppose app.js imports foo.js which imports bar.js. Then, the user changes foo.js to also import baz.js.

The foo.js MappedAsset will now have TWO JavaScriptImport objects (for bar.js and baz.js). However, when we calculate the preloads, this happens:

  1. We load the cached MappedAsset for app.js because this file has not changed
  2. It correctly has 1 JavaScriptImport for foo.js
  3. But the JavaScriptImport->asset property holds an OUT-OF-DATE version of the MappedAsset for foo.js... because it was cached inside the MappedAsset structure for app.js. This out-of-date MappedAsset for foo.js only contains the ONE JavaScript import.

The result is that baz.js will be missing from the preloads.

This PR breaks the structure by only storing the asset's logical path (and sourcePath - needed by the cache system). Then, at runtime, we load the fresh MappedAsset from the logical path.

Cheers!

@weaverryan weaverryan force-pushed the asset-mapper-avoid-caching-mapped-asset branch from c6009ce to caf7fcb Compare November 10, 2023 02:27
The problem is that these could get out of date, allowing asset Foo to have a
JavaScript import for the MappedAsset for Bar, but it is out of date because
Bar has since changed.
@weaverryan weaverryan force-pushed the asset-mapper-avoid-caching-mapped-asset branch from caf7fcb to bb5ef88 Compare November 10, 2023 02:31
@fabpot fabpot merged commit a647f55 into symfony:6.4 Nov 10, 2023
This was referenced Nov 10, 2023
@weaverryan weaverryan deleted the asset-mapper-avoid-caching-mapped-asset branch November 11, 2023 01:35
xabbuh added a commit that referenced this pull request Nov 24, 2023
This PR was merged into the 6.4 branch.

Discussion
----------

[AssetMapper] Fix windows ci fail

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fixes CI
| License       | MIT

I missed the windows-only test in #52523.

Cheers!

Commits
-------

e172b68 [AssetMapper] Fixing out-of-date test on Windows
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.

4 participants