Skip to content

Commit dec93e9

Browse files
bug #50476 [FrameworkBundle] remove support for preloading ESM using headers (dunglas)
This PR was merged into the 6.3 branch. Discussion ---------- [FrameworkBundle] remove support for preloading ESM using headers | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | n/a | License | MIT | Doc PR | n/a Sorry to be that late on this one. It looks like preloading ESM using HTTP headers (and so using 103 Early Hints) doesn't work, at least for now: WICG/import-maps#273 (comment) ImportMap must be defined before downloading any ESM, and by definition HTTP headers are sent before importmap definition (it's currently not possible to define importmap using headers). I don't know why I didn't caught this during my previous testing session, but now I get this error in the console when using this feature (which, according to the previously mentioned issue, is expected): ``` An import map is added after module script load was triggered. Uncaught TypeError: Failed to resolve module specifier "app". Relative references must start with either "/", "./", or "../". ``` This patch simply removes this feature, which is entirely non-functional and misleading for the end user. Commits ------- 7776c28 [FrameworkBundle] remove support for preloading ESM modules using headers
2 parents b587099 + 7776c28 commit dec93e9

File tree

2 files changed

+1
-15
lines changed

2 files changed

+1
-15
lines changed

src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Psr\Container\ContainerInterface;
1515
use Psr\Link\EvolvableLinkInterface;
1616
use Psr\Link\LinkInterface;
17-
use Symfony\Component\AssetMapper\ImportMap\ImportMapManager;
1817
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
1918
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
2019
use Symfony\Component\Form\Extension\Core\Type\FormType;
@@ -97,7 +96,6 @@ public static function getSubscribedServices(): array
9796
'security.csrf.token_manager' => '?'.CsrfTokenManagerInterface::class,
9897
'parameter_bag' => '?'.ContainerBagInterface::class,
9998
'web_link.http_header_serializer' => '?'.HttpHeaderSerializer::class,
100-
'asset_mapper.importmap.manager' => '?'.ImportMapManager::class,
10199
];
102100
}
103101

@@ -412,7 +410,7 @@ protected function addLink(Request $request, LinkInterface $link): void
412410
/**
413411
* @param LinkInterface[] $links
414412
*/
415-
protected function sendEarlyHints(iterable $links = [], Response $response = null, bool $preloadJavaScriptModules = false): Response
413+
protected function sendEarlyHints(iterable $links = [], Response $response = null): Response
416414
{
417415
if (!$this->container->has('web_link.http_header_serializer')) {
418416
throw new \LogicException('You cannot use the "sendEarlyHints" method if the WebLink component is not available. Try running "composer require symfony/web-link".');
@@ -421,17 +419,6 @@ protected function sendEarlyHints(iterable $links = [], Response $response = nul
421419
$response ??= new Response();
422420

423421
$populatedLinks = [];
424-
425-
if ($preloadJavaScriptModules) {
426-
if (!$this->container->has('asset_mapper.importmap.manager')) {
427-
throw new \LogicException('You cannot use the JavaScript modules method if the AssetMapper component is not available. Try running "composer require symfony/asset-mapper".');
428-
}
429-
430-
foreach ($this->container->get('asset_mapper.importmap.manager')->getModulesToPreload() as $url) {
431-
$populatedLinks[] = new Link('modulepreload', $url);
432-
}
433-
}
434-
435422
foreach ($links as $link) {
436423
if ($link instanceof EvolvableLinkInterface && !$link->getRels()) {
437424
$link = $link->withRel('preload');

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ public function testSubscribedServices()
7474
'security.token_storage' => '?Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorageInterface',
7575
'security.csrf.token_manager' => '?Symfony\\Component\\Security\\Csrf\\CsrfTokenManagerInterface',
7676
'web_link.http_header_serializer' => '?Symfony\\Component\\WebLink\\HttpHeaderSerializer',
77-
'asset_mapper.importmap.manager' => '?Symfony\\Component\\AssetMapper\\ImportMap\\ImportMapManager',
7877
];
7978

8079
$this->assertEquals($expectedServices, $subscribed, 'Subscribed core services in AbstractController have changed');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy