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

update script behavior section #6798

Merged
merged 14 commits into from
Mar 9, 2024
Merged
Prev Previous commit
Next Next commit
Update src/content/docs/en/guides/view-transitions.mdx
Co-authored-by: Martin Trapp <94928215+martrapp@users.noreply.github.com>
  • Loading branch information
OliverSpeir and martrapp authored Feb 6, 2024
commit 790c792c52a52613e021f8cdb8c7613a18c21239
2 changes: 1 addition & 1 deletion src/content/docs/en/guides/view-transitions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ When navigating between pages with the `<ViewTransitions />` component, scripts

Bundled module scripts, which are the default scripts in Astro, only ever execute once. If a bundled module script exists on pages that are transitioned to after its initial execution they will be ignored. Inline scripts, ones with `is:inline` attribute, will not reexecute if they exist on both the page being transitioned to and the one the user is currently on.

Unlike module scripts, inline scripts have the potential to be reexcuted during a users visit to a site, if they exist on a page that is visited multiple times. Inline scripts might also reexecute if they exist on some pages but not all, if a user goes to a page without the script then back to one with the script it will be reexecuted.
Unlike bundled module scripts, inline scripts have the potential to be reexcuted during a users visit to a site, if they exist on a page that is visited multiple times. Inline scripts might also reexecute if they exist on some pages but not all, if a user goes to a page without the script then back to one with the script it will be reexecuted.

If you have code that sets up global state in an inline script, this state will need to take into account that the script might execute more than once. Check for the global state in your `<script>` tag, and conditionally execute your code where possible. This works because `window` is preserved.

Expand Down
Loading