Skip to content

Commit

Permalink
docs: update v5 upgrade guide to mention change in script behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
MoustaphaDev committed Jan 10, 2025
1 parent 37950dc commit 181b74f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/content/docs/en/guides/upgrade-to/v5.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,25 @@ In Astro v4.x, `experimental.directRenderScript` was an optional flag to directl

Astro 5.0 removes this experimental flag and makes this the new default behavior in Astro: scripts are no longer hoisted to the `<head>`, multiple scripts on a page are no longer bundled together, and a `<script>` tag may interfere with CSS styling.

Additionally, conditionally rendered scripts were previously implicitly inlined, as if an `is:inline` directive was automatically added to them. In Astro 5, this behavior is no longer implicit.

#### What should I do?

If you previously had conditionally rendered `<script>` tags, you will need to add an `is:inline` attribute to preserve the same behavior as before:

```astro title="src/components/MyComponent.astro" ins="is:inline"
---
type Props
showAlert: boolean
}
const { showAlert } = Astro.props;
---
{
showAlert && <script is:inline>alert("Some very important code!!")</script>
}
```

Please review your `<script>` tags and ensure they behave as desired.

<ReadMore>Read more about [using `script` tags in Astro](/en/guides/client-side-scripts/#using-script-in-astro).</ReadMore>
Expand Down

0 comments on commit 181b74f

Please sign in to comment.