Skip to content

Commit

Permalink
bug #52108 [AssetMapper] Link needs as="style" (weaverryan)
Browse files Browse the repository at this point in the history
This PR was merged into the 6.4 branch.

Discussion
----------

[AssetMapper] Link needs as="style"

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Mentioned on symfony/recipes#1245 (comment)
| License       | MIT

Hi!

The `as="style"` is required. It was missing from the docs (I'll make a PR there) and so I forgot it :). Tested on a real project to verify the warning was gone.

Cheers!

Commits
-------

6c55206 [AssetMapper] Link needs as="style"
  • Loading branch information
nicolas-grekas committed Oct 17, 2023
2 parents 43bcef0 + 6c55206 commit b9122bc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private function createAttributesString(array $attributes): string

private function addWebLinkPreloads(Request $request, array $cssLinks): void
{
$cssPreloadLinks = array_map(fn ($url) => new Link('preload', $url), $cssLinks);
$cssPreloadLinks = array_map(fn ($url) => (new Link('preload', $url))->withAttribute('as', 'style'), $cssLinks);

if (null === $linkProvider = $request->attributes->get('_links')) {
$request->attributes->set('_links', new GenericLinkProvider($cssPreloadLinks));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public function testItAddsPreloadLinks()
$this->assertInstanceOf(GenericLinkProvider::class, $linkProvider);
$this->assertCount(1, $linkProvider->getLinks());
$this->assertSame(['preload'], $linkProvider->getLinks()[0]->getRels());
$this->assertSame(['as' => 'style'], $linkProvider->getLinks()[0]->getAttributes());
$this->assertSame('/assets/styles/app-preload-d1g35t.css', $linkProvider->getLinks()[0]->getHref());
}
}

0 comments on commit b9122bc

Please sign in to comment.