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
Make Lava Application
Make an endpoint with two javascript commands with the same id.
Add Lava Application content to page, add <div hx-get="<the path to endpoint>" hx-trigger="load"></div>
See multiple scripts rendered and running
Issue Confirmation
[X] Perform a search on the Github Issues to see if your bug or enhancement is already reported.
[X] Try to reproduce the problem on a fresh install or on the demo site.
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 forhtmx: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
<div hx-get="<the path to endpoint>" hx-trigger="load"></div>
Issue Confirmation
Rock Version
16.6