Skip to content

Add filament scripts attributes#19474

Open
helturkey wants to merge 3 commits intofilamentphp:5.xfrom
helturkey:adding-filament-scripts-attributes
Open

Add filament scripts attributes#19474
helturkey wants to merge 3 commits intofilamentphp:5.xfrom
helturkey:adding-filament-scripts-attributes

Conversation

@helturkey
Copy link
Contributor

What does this PR do?

Adds an attributes parameter to the @filamentScripts Blade directive and renderScripts(), allowing arbitrary HTML attributes to be applied to every rendered <script> tag including the window.filamentData block.

Usage

@filamentScripts(attributes: ['data-cfasync' => 'false'])

Or globally via config/filament.php:

'scripts' => [
    'attributes' => [
        // 'data-cfasync' => 'false',
    ],
],

Usage Case?

As an Example Cloudflare Rocket Loader defers JavaScript execution by default, which breaks Filament forms in blade, While admin panel could be filtered or bypassed using cloudflare rules, it may be difficult to bypass every single uri, you are using filament form in. Cloudflare requires data-cfasync="false" on every <script> tag to opt out. Without this, users had to override the entire @filamentScripts directive manually.

Changes

I tried to make the minimal impacts or changes possible, so the changes are:

  • AssetManager::renderScripts() now accepts array $attributes = [], merged with config('filament.scripts.attributes') (inline wins on conflict)
  • Js::getExtraAttributesHtml() supports integer-keyed (valueless) attributes e.g. ['async'] renders as async not 0="async"
  • Attributes are applied to both <script src=...> tags and the window.filamentData inline block

Tests

./vendor/bin/pest tests/src/Support/BladeDirectives/FilamentScriptsAttributesTest.php

@github-project-automation github-project-automation bot moved this to Todo in Roadmap Mar 11, 2026
@helturkey helturkey force-pushed the adding-filament-scripts-attributes branch 2 times, most recently from 6aefb06 to cafcf2c Compare March 12, 2026 00:55
@danharrin danharrin added enhancement New feature or request pending review labels Mar 12, 2026
@danharrin danharrin added this to the v4 milestone Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request pending review

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants