-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Prevent rerunning scripts already ran in router #12985
Conversation
In a long session you might navigate between several pages, some contain the script and some not, but nevertheless the script should run a total of 1 time. This also helps with smaller bundled scripts in production, where some are inlined.
🦋 Changeset detectedLatest commit: 222c00a 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 |
CodSpeed Performance ReportMerging #12985 will not alter performanceComparing Summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like what we discussed on discord ;-)
Left two comments.
With that change in place, we can also remove astro/packages/astro/src/transitions/swap-functions.ts Lines 9 to 30 in 0968069
and
|
@martrapp |
!preview router-noexec |
Snapshots have been released for the following packages:
Publish Log
Build Log
|
Ah, right. The job of |
@martrapp I created a preview release, can you let the people who encountered the bug to try it out? |
Yes will do! Thanks a lot! Btw: taking |
We got 1 confirmation that it fixes their issue. Enough to merge this? |
Hi @matthewp, |
Looks like that actually broke tests :( |
Yes, the code that checks for same src resp. same text re-establishes the previous semantics. &&
// Inline
((!s1.src && s1.textContent === s2.textContent) ||
// External
(s1.src && s1.type === s2.type && s1.src === s2.src)) and all should be fine. |
@martrapp passing now, would appreciate another review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the two marked changes, the updates look good to me now. At least they match what was discussed.
I'm still not sure how many sites this will be a breaking change for.
I also have some slight concerns about the size of keys that could accumulate over time, but who really writes huge inline scripts?
I was surprised that we had no tests for data-astro-rerun, so I added one.
But you must explicitly activate it, yet.
// the old script is in the new document and doesn't have the rerun attribute | ||
// we mark it as executed to prevent re-execution | ||
s2.dataset.astroExec = ''; | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems this is the real cause of what let the tests fail last time. We should definitively visit all scripts, and not break after the first known one ;-)
@@ -138,6 +139,7 @@ function runScripts() { | |||
if (script.dataset.astroExec === '') continue; | |||
const type = script.getAttribute('type'); | |||
if (type && type !== 'module' && type !== 'text/javascript') continue; | |||
if (detectScriptExecuted(script)) continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite sure about your last commit but to me it looks as if it would simply prevent all reruns including those with data-astro-rerun
https://docs.astro.build/en/guides/view-transitions/#script-re-execution should be updated. |
Changes
Testing
Docs
N/A, bug fix.