Triumph-Tech / Triumph-Helix

A repo that allows for reporting issues related to Helix.
https://helix.triumph.tech
5 stars 0 forks source link

Duplicating JavaScript and Stylesheet Commands within Lava Applications #10

Open jamrphy-bwd opened 1 month ago

jamrphy-bwd commented 1 month ago

Description

JavaScript and StyleSheet commands do not respect the id parameter in the context of Lava Applications, because Lava Applications do not provide a Page context to search for the element with the existing id. So, each call to those commands results in an inline-rendered <script> or <style>.

Actual Behavior

Using multiple JavaScript (or StyleSheet) commands with the same id parameter renders all of them, rather than limiting them to one per page per unique id.

Expected Behavior

Only one <script> should be rendered to the page per unique id. Importantly, this should remain true whether the {% javascript id:'unique' %} commands are executed in the same request or in different requests for the same page.

Possibly, some metadata, such as a data-lava-id HTML attribute, could be added to the server rendering of <script> and <style> elements from lava (if applicable). Then, the helix script could watch for htmx:beforeSwap, test for duplicates using the metadata, and modify the event.detail.serverResponse property to remove duplicate scripts or stylesheets.

I'm sure there are other ways to approach this, but that's one idea.

Steps to Reproduce

Issue Confirmation

Rock Version

16.6