Skip to content

Commit

Permalink
Update PreloadAssetsEventListener to use crossorigin bundle config op…
Browse files Browse the repository at this point in the history
…tion value
  • Loading branch information
andyexeter committed Feb 9, 2024
1 parent 2a4cfa1 commit 59d724b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function load(array $bundleConfigs, ContainerBuilder $container): void
$container->setParameter('pentatrion_vite.absolute_url', $bundleConfig['absolute_url']);
$container->setParameter('pentatrion_vite.proxy_origin', $bundleConfig['proxy_origin']);
$container->setParameter('pentatrion_vite.throw_on_missing_entry', $bundleConfig['throw_on_missing_entry']);
$container->setParameter('pentatrion_vite.crossorigin', $bundleConfig['crossorigin']);

if (
count($bundleConfig['configs']) > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
class PreloadAssetsEventListener implements EventSubscriberInterface
{
private EntrypointRenderer $entrypointRenderer;
private string|bool $crossOriginAttribute;

public function __construct(EntrypointRenderer $entrypointRenderer)
public function __construct(EntrypointRenderer $entrypointRenderer, string|bool $crossOriginAttribute)
{
$this->entrypointRenderer = $entrypointRenderer;
$this->crossOriginAttribute = $crossOriginAttribute;
}

public function onKernelResponse(ResponseEvent $event): void
Expand All @@ -39,7 +41,7 @@ public function onKernelResponse(ResponseEvent $event): void
$link = $this->createLink('preload', $href)->withAttribute('as', 'script');

if ('module' === $tag->getAttribute('type')) {
$link = $link->withAttribute('crossorigin', true);
$link = $link->withAttribute('crossorigin', $this->crossOriginAttribute ?: 'anonymous');
}

$linkProvider = $linkProvider->withLink($link);
Expand Down
1 change: 1 addition & 0 deletions src/vite-bundle/src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ services:
tags: ["kernel.event_subscriber"]
arguments:
- "@pentatrion_vite.entrypoint_renderer"
- "%pentatrion_vite.crossorigin%"

pentatrion_vite.file_accessor:
class: Pentatrion\ViteBundle\Service\FileAccessor
Expand Down

0 comments on commit 59d724b

Please sign in to comment.