Skip to content

Commit 7d024fc

Browse files
MoustaphaDevsarah11918ArmandPhilippot
authored
Update mention about script processing behavior in JSX expression (#10656)
* Update mention about script behavior in JSX expression * docs: update v5 upgrade guide to mention change in script behavior * reorder for structure * apply Armand's review suggestion Co-authored-by: Armand Philippot <[email protected]> --------- Co-authored-by: Sarah Rainsberger <[email protected]> Co-authored-by: Armand Philippot <[email protected]>
1 parent c31c02a commit 7d024fc

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/content/docs/en/guides/client-side-scripts.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ To prevent Astro from processing a script, add the `is:inline` directive.
8585
```
8686

8787
:::note
88-
Astro will not process your script tags in some situations. In particular, adding `type="module"` or any attribute other than `src` to a `<script>` tag will cause Astro to treat the tag as if it had an `is:inline` directive. The same will be true when the script is written in a JSX expression.
88+
Astro will not process your script tags in some situations. In particular, adding `type="module"` or any attribute other than `src` to a `<script>` tag will cause Astro to treat the tag as if it had an `is:inline` directive.
8989
:::
9090

9191
<ReadMore>See our [directives reference](/en/reference/directives-reference/#script--style-directives) page for more information about the directives available on `<script>` tags.</ReadMore>

src/content/docs/en/guides/upgrade-to/v5.mdx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,14 +532,29 @@ In the event of route collisions, where two routes of equal route priority attem
532532

533533
<SourcePR number="11791" title="Make directRenderScript the default"/>
534534

535-
In Astro v4.x, `experimental.directRenderScript` was an optional flag to directly render `<scripts>` as declared in `.astro` files (including existing features like TypeScript, importing `node_modules`, and deduplicating scripts). This strategy prevented scripts from being executed in places where they were not used.
535+
In Astro v4.x, `experimental.directRenderScript` was an optional flag to directly render `<scripts>` as declared in `.astro` files (including existing features like TypeScript, importing `node_modules`, and deduplicating scripts). This strategy prevented scripts from being executed in places where they were not used. Additionally, conditionally rendered scripts were previously implicitly inlined, as if an `is:inline` directive was automatically added to them.
536536

537-
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.
537+
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 are no longer implicitly inlined.
538538

539539
#### What should I do?
540540

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

543+
If you previously had conditionally rendered `<script>` tags, you will need to add an `is:inline` attribute to preserve the same behavior as before:
544+
545+
```astro title="src/components/MyComponent.astro" ins="is:inline"
546+
---
547+
type Props = {
548+
showAlert: boolean
549+
}
550+
551+
const { showAlert } = Astro.props;
552+
---
553+
{
554+
showAlert && <script is:inline>alert("Some very important code!!")</script>
555+
}
556+
```
557+
543558
<ReadMore>Read more about [using `script` tags in Astro](/en/guides/client-side-scripts/#using-script-in-astro).</ReadMore>
544559

545560
## Breaking Changes

0 commit comments

Comments
 (0)