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

Hoisted <script> behavior in v5 #13309

Open
1 task
dylanfisher opened this issue Feb 24, 2025 · 3 comments
Open
1 task

Hoisted <script> behavior in v5 #13309

dylanfisher opened this issue Feb 24, 2025 · 3 comments
Labels
needs repro Issue needs a reproduction

Comments

@dylanfisher
Copy link

Astro Info

Astro                    v5.3.1
Node                     v20.18.0
System                   macOS (arm64)
Package Manager          pnpm
Output                   server
Adapter                  @astrojs/vercel
Integrations             astro-html-beautifier
                         @sanity/astro
                         @astrojs/react

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

No response

Describe the Bug

https://docs.astro.build/en/guides/upgrade-to/v5/#script-tags-are-rendered-directly-as-declared

In astro v4 <script> tags were hoisted to the head. In v5, they are now rendered in place by default.

Is there a way to restore the previous hoisting functionality? The reason we noticed this change is because we have CSS that targets next elements (e.g. .component + footer) that no longer work because a <script> tag is inserted between the component and the footer.

Additionally, the hoisted script tags were previously compiled into a single javascript file in v4. Now, those <script> tags have the javascript directly rendered in the HTML of the page.

What's the expected result?

The ability to specify a hoisted script behavior to match v4, or confirmation that hoisted scripts are no longer supported.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-3h3aehry?file=src%2Fcomponents%2FWelcome.astro

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Feb 24, 2025
@J-env
Copy link

J-env commented Feb 25, 2025

I have similar problem. #13002

Componentized <script> tags are rendered directly as declared, which has many strange problems.

  1. In template:
  2. In Alpinejs/petite-vue:
  3. Custom Integration (php):
---
import MyComponent from '@/components/MyComponent.astro'
---

<div>

<template><MyComponent /></template>

<!-- <div x-for="item of list"><MyComponent /></div> -->

<!-- {`<?php if ($uid > 0): ?>`}<div><MyComponent /></div>{`<?php endif; ?>`} -->

 <MyComponent />
</div>

MyComponent.astro

---
---

<script src="./MyComponent.ts"></script>
  1. When there are many components on the page, there are too many script tags

@ematipico ematipico added the needs repro Issue needs a reproduction label Feb 25, 2025
Copy link
Contributor

Hello @dylanfisher. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs repro will be closed if they have no activity within 3 days.

@github-actions github-actions bot removed the needs triage Issue needs to be triaged label Feb 25, 2025
@ematipico
Copy link
Member

@dylanfisher please provide a valid reproduction, your reproduction just has script that behaves as expected, as per v5.

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

No branches or pull requests

3 participants