Commit 999a7dd
fix: preserve inline styles and font preloads during ClientRouter head swap (#15514)
* fix: preserve inline styles and font preloads during ClientRouter head swap
During client-side navigation with ClientRouter, swapHeadElements() only
preserved elements with data-astro-transition-persist and stylesheet links.
Inline <style> tags (including @font-face declarations from <Font>) were
removed and re-appended on every navigation, forcing the browser to
re-evaluate them and triggering a visible font flash (FOUT).
This extends persistedHeadElement() to also match:
- Inline <style> elements by their text content
- Font preload links (link[rel=preload][as=font]) by href
When an identical element exists in both the old and new document head,
it stays in the DOM instead of being removed and re-inserted.
Fixes #15465
* add changeset
* Add e2e test for inline style and font preload persistence
Add a test that verifies inline <style> elements (e.g. @font-face
declarations) and font preload links survive head swaps during
client-side navigation, preventing FOUT (Flash of Unstyled Text).
The test navigates between two pages sharing identical inline styles
and font preloads, and asserts that the original DOM nodes persist
rather than being removed and re-inserted.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: resolve lint errors and flaky e2e test for font persistence
Remove unused variables (styleIdBefore, preloadIdBefore) to fix biome
lint errors. Replace fragile exact style count comparison with
greaterThan(0) checks, since Astro may inject additional style elements
during client-side navigation. Use data-attribute selectors to directly
query the marked DOM nodes instead of relying on querySelector order.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Make the test a bit more concise
* Update fix-font-head-swap.md
---------
Co-authored-by: Martin Trapp <94928215+martrapp@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent b30a2c4 commit 999a7dd
5 files changed
Lines changed: 84 additions & 0 deletions
File tree
- .changeset
- packages/astro
- e2e
- fixtures/view-transitions/src/pages
- src/transitions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1759 | 1759 | | |
1760 | 1760 | | |
1761 | 1761 | | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
1762 | 1778 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
164 | 181 | | |
165 | 182 | | |
166 | 183 | | |
| |||
0 commit comments