-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent rerunning scripts already ran in router (#12985)
* Prevent rerunning scripts already ran in router 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. * Add changeset * better key * more concise * review changes * move stuff around * fix types * take Martin's suggestion * run detection when executing scripts * adds an e2e test for data-astro-rerun * fix support for data-astro-rerun --------- Co-authored-by: Martin Trapp <[email protected]>
- Loading branch information
Showing
9 changed files
with
120 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Prevent re-executing scripts in client router |
16 changes: 16 additions & 0 deletions
16
packages/astro/e2e/fixtures/view-transitions/src/pages/eight.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
import Layout from '../components/Layout.astro'; | ||
import { ClientRouter } from 'astro:transitions'; | ||
Astro.response.headers.set('Content-Type', 'text/html ; charset=utf-8'); | ||
--- | ||
<html> | ||
<head> | ||
<ClientRouter handleForms /> | ||
</head> | ||
<body> | ||
<p id="eight">Page 8</p> | ||
|
||
<a id="click-one" href="/one">go to 1</a> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/astro/e2e/fixtures/view-transitions/src/pages/page1-with-scripts.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
import {ClientRouter} from "astro:transitions"; | ||
--- | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<ClientRouter /> | ||
<title>Page 1</title> | ||
<script is:inline data-astro-rerun>console.log('[test] 3');</script> | ||
<script is:inline>console.log('[test] 1');</script> | ||
</head> | ||
<body> | ||
<a id="link" href="/page2-with-scripts">to page 2</a> | ||
</body> | ||
</html> |
15 changes: 15 additions & 0 deletions
15
packages/astro/e2e/fixtures/view-transitions/src/pages/page2-with-scripts.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
import {ClientRouter} from "astro:transitions"; | ||
--- | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<ClientRouter /> | ||
<title>Page 2</title> | ||
<script is:inline data-astro-rerun>console.log('[test] 2');</script> | ||
<script is:inline>console.log('[test] 1');</script> | ||
</head> | ||
<body> | ||
<a id="link" href="/page3-with-scripts">to page 3</a> | ||
</body> | ||
</html> |
16 changes: 16 additions & 0 deletions
16
packages/astro/e2e/fixtures/view-transitions/src/pages/page3-with-scripts.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
import {ClientRouter} from "astro:transitions"; | ||
--- | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<ClientRouter /> | ||
<title>Page 3</title> | ||
<script is:inline>console.log('[test] 1');</script> | ||
<script is:inline data-astro-rerun>console.log('[test] 2');</script> | ||
<script is:inline data-astro-rerun>console.log('[test] 3');</script> | ||
</head> | ||
<body> | ||
<a id="link" href="/page1-with-scripts">to page 1</a> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters