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

Execute scripts on page navigation (view transitions) #7786

Merged
merged 2 commits into from
Jul 25, 2023
Merged

Conversation

matthewp
Copy link
Contributor

@matthewp matthewp commented Jul 24, 2023

Changes

  • DOMParser creates scripts that are non executable, event after inserting into the page.
  • This makes it so that scripts are always executed. If they have already run we reinsert them. That means for inline classic scripts those will re-run. Module scripts will not.
  • This approach was chosen mostly because it's the last amount of code. It also aligns with what Swup does it.
  • Adds the astro:load even that you can listen to if you need to rerun something on page navigation.
  • Fixes View Transition resets html attributes #7765

Testing

  • Test added to verify the astro:load event fire on forward navigation.
  • Test added to verify astro:load fires on direct page navigation (MPA).

Docs

@changeset-bot
Copy link

changeset-bot bot commented Jul 24, 2023

🦋 Changeset detected

Latest commit: 0d0dbde

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jul 24, 2023
@matthewp matthewp marked this pull request as ready for review July 24, 2023 19:22
Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick comment on the changeset text, @matthewp, and just a quick question whether we should be adding astro:load as part of the docs PR (since I don't think there's anything existing there) that I'll also bring up there!

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved by docs!

@doganalper
Copy link
Contributor

I think this would solve problem I'm facing currently. I wanted to add view transitions but since I have dark/light theme it breaks logic I have and themes not working properly. Good work @matthewp!

@matthewp matthewp merged commit 188eedd into main Jul 25, 2023
@matthewp matthewp deleted the vt-load branch July 25, 2023 12:35
@astrobot-houston astrobot-houston mentioned this pull request Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

View Transition resets html attributes
4 participants