Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javascript file for components not loaded when in a template tag #12940

Open
1 task done
Aviortheking opened this issue Jan 8, 2025 · 1 comment
Open
1 task done
Labels
needs triage Issue needs to be triaged

Comments

@Aviortheking
Copy link

Aviortheking commented Jan 8, 2025

Astro Info

$ astro info
Astro                    v5.1.3
Node                     v22.11.0
System                   Linux (x64)
Package Manager          bun
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

Firefox

Describe the Bug

In my project, I use templates to load some components, and affect them with their respective Javascript script when they are cloned into the real deal.

It seems that Astro 5 changed how scripts are loaded and exclude scripts have at least one instance of them loaded into a template tag (even the others outside the template tag don't work)

What's the expected result?

It should load the scripts even if they are only in a template tag

Link to Minimal Reproducible Example

https://github.com/Aviortheking/astro-template-not-running-js

Participation

  • I am willing to submit a pull request for this issue.

note :

It also happens on 5.1.4 released recently

@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jan 8, 2025
@bluwy
Copy link
Member

bluwy commented Jan 9, 2025

It could be possible for the Astro compiler to add a hint that if the script is in a <template>, then it should always render the script. But if the <template> is in the parent file, and the child file has <script>, then it wouldn't be possible for the compiler to detect so. We also can't detect in runtime as the HTML are directly rendered as strings without any DOM info.

I think the best way here is to adapt to the new behaviour of it only rendering once. Could it be moved outside of the template tag? In Astro 4, that would've also happened in practice unconditionally. If the script doesn't need to be processed, you can use <script is:inline>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

2 participants