Repository navigation
Load the stylesheet and script only on the pages that show comments - #128
Open
theofanisv wants to merge 2 commits into
Open
theofanisv wants to merge 2 commits into
theofanisv wants to merge 2 commits into
Conversation
Filament prints every registered asset that is not loaded on request on every page of every panel. An app with several panels, where only one of them shows comments, loaded the editor's script (with Tiptap) and the stylesheet on all pages of all of them, including public pages that never show a comment. Both assets are now registered as loaded on request. A new `commentions::assets` view adds them with Livewire's `@assets`, and the comments, comment list and comment views include it, so a page gets them once, in its head, on the first render or with the Livewire update that brings the comments in. The script registered the editor's Alpine component on `alpine:init`, which has already fired when the script arrives with a Livewire update, for example comments opened in a modal. It now registers at once when Alpine is already there, and waits for `alpine:init` otherwise.
Member
|
@theofanisv Can you please fix the static analysis check that are failing in CI? |
Contributor
Author
|
Thanks, fixed in 5ab2e6a: the new test now uses Pest's |
nathanheffley
approved these changes
Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello,
I run an app with several Filament panels: an admin panel for the staff, a public panel that customers open on their phones, and a panel for kiosk machines. Only the admin panel shows comments, and only on a few of its pages. Filament prints every registered asset that is not loaded on request on every page of every panel, so every page of all three panels loaded the comment editor's script, which bundles Tiptap, and the stylesheet, including the pages customers open on their phones.
What this changes
->loadedOnRequest().commentions::assetsview adds them with Livewire's@assets, and thecomments,comment-listandcommentviews include it. Livewire puts them in the page's<head>on the first render, or adds them with the Livewire update that brings the comments in (a modal, a tab, a SPA navigation). Since it is one@assetsblock, a page gets each file once however many comment components it shows.editorAlpine component onalpine:init. When the script arrives with a Livewire update, Alpine has already started and that event will not fire again, so it now registers at once whenwindow.Alpineis there and waits foralpine:initotherwise.resources/dist/commentions.jsis rebuilt withnode bin/build.js; a build of the unchanged source gave back the committed file byte for byte, so the only difference in it is this one.Nothing changes on the pages that show comments; every other page stops loading the two files.
How it was tested
tests/Livewire/CommentsTest.phpchecks that both assets are loaded on request, and that a page rendering theCommentscomponent has both files while a page without it has neither. It fails without the change.Schema::dropAllTables()inTestCase::setUpDatabase()fails on an in-memory SQLite database ("table sqlite_master may not be modified"), with or without this change, so I ran the suite against a temporary SQLite file.Thank you for the plugin.