You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR was squashed before being merged into the 6.4 branch.
Discussion
----------
[AssetMapper] Fix file deleting errors & remove nullable MappedAsset on JS import
| Q | A
| ------------- | ---
| Branch? | 6.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Issues | None
| License | MIT
Hi!
This PR accomplishes 2 things:
A) If `app.js` imported `foo.js`, and you deleted `foo.js`, you got a big, unobvious error from Symfony. This was because the `MappedAsset` behind `app.js` remained cached, including the `JavaScriptImport` for `foo.js`. So then, the system was surprised when `app.js` had this `JavaScriptImport`... but the underlying file didn't exist. The fix was to add a `FileExistenceResource` for `foo.js`. We don't need to update the `app.js` cache if `foo.js` changes, but we DO need to update it if `foo.js` no longer exists (so that we can create a new `MappedAsset` without the import).
B) Upon looking at this, previously, `JavaScriptImport.asset` was nullable. That doesn't make sense, now that all vendor files are downloaded locally and exist in the AssetMapper. The `MappedAsset.javascriptImports` are used to implicitly add importmap entries for relative assets (which already required a `MappedAsset`) and to preload other dependencies. Previously, we added a `JavaScriptImport` with a null asset for things like absolute imports (`import 'https://example.com/foo.js') or bare imports that we couldn't find. But we can't preload things like this anyway - or we shouldn't bother to in the case of an absolute assets.
For (B), trying to tighten things up and do LESS, if we don't need it.
Cheers!
Commits
-------
f1708aa [AssetMapper] Fix file deleting errors & remove nullable MappedAsset on JS import
Copy file name to clipboardExpand all lines: src/Symfony/Component/AssetMapper/ImportMap/JavaScriptImport.php
+4-8
Original file line number
Diff line number
Diff line change
@@ -19,19 +19,15 @@
19
19
finalclass JavaScriptImport
20
20
{
21
21
/**
22
-
* @param string $importName The name of the import needed in the importmap, e.g. "/foo.js" or "react"
23
-
* @param bool $isLazy Whether this import was lazy or eager
24
-
* @param MappedAsset|null $asset The asset that was imported, if known - needed to add to the importmap, also used to find further imports for preloading
25
-
* @param bool $addImplicitlyToImportMap Whether this import should be added to the importmap automatically
22
+
* @param string $importName The name of the import needed in the importmap, e.g. "/foo.js" or "react"
23
+
* @param MappedAsset $asset The asset that was imported
24
+
* @param bool $addImplicitlyToImportMap Whether this import should be added to the importmap automatically
26
25
*/
27
26
publicfunction__construct(
28
27
publicreadonlystring$importName,
28
+
publicreadonlyMappedAsset$asset,
29
29
publicreadonlybool$isLazy = false,
30
-
publicreadonly ?MappedAsset$asset = null,
31
30
publicbool$addImplicitlyToImportMap = false,
32
31
) {
33
-
if (null === $asset && $addImplicitlyToImportMap) {
34
-
thrownew \LogicException(sprintf('The "%s" import cannot be automatically added to the importmap without an asset.', $this->importName));
0 commit comments