-
-
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
base: main
Are you sure you want to change the base?
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: fe845fe 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.
await page.goBack(); | ||
p = page.locator('#one'); | ||
await expect(p, 'should have content').toHaveText('Page 1'); | ||
|
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.
Navigation across pages 3 and 5 will do a full page load as those don't use the client router.
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.
Ah oops, ok I'll create a new page that does use it then.
function runScripts() { | ||
let wait = Promise.resolve(); | ||
for (const script of document.getElementsByTagName('script')) { | ||
if (script.dataset.astroExec === '') continue; | ||
if (detectScriptExecuted(script)) continue; | ||
const type = script.getAttribute('type'); | ||
if (type && type !== 'module' && type !== 'text/javascript') 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.
maybe move checking the type attribute two lines up as we do not need to remember e.g. speculation rules, import maps, or partytown scripts
With that change in place, we can also remove astro/packages/astro/src/transitions/swap-functions.ts Lines 9 to 30 in 0968069
and
|
Changes
Testing
Docs
N/A, bug fix.