Skip to content

Commit 1bcb43b

Browse files
authored
Prebundle dev toolbar entrypoint in client environment (#16480)
* prebundle dev toolbar entrypoint in client optimizeDeps * fix e2e audit tests: reload so images are cached before audit runs * wait for images to load in audit instead of skipping them * Reword changeset to be user-facing
1 parent 93101cc commit 1bcb43b

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Fixes an unnecessary full page reload on first navigation during dev

packages/astro/src/runtime/client/dev-toolbar/apps/audit/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,13 @@ export default {
194194
return;
195195
}
196196

197-
// If the element is an image but not yet loaded, ignore it
198-
// TODO: We shouldn't ignore this, because it is valid for an image to not be loaded at start (e.g. lazy loading)
197+
// If the element is an image that hasn't loaded yet, wait for it so that
198+
// position-based checks (e.g. above/below the fold) have accurate layout data.
199199
if (originalElement.nodeName === 'IMG' && !(originalElement as HTMLImageElement).complete) {
200-
return;
200+
await new Promise<void>((resolve) => {
201+
originalElement.addEventListener('load', () => resolve(), { once: true });
202+
originalElement.addEventListener('error', () => resolve(), { once: true });
203+
});
201204
}
202205

203206
audits.push({

packages/astro/src/vite-plugin-environment/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export function vitePluginEnvironment({
8989
include: [
9090
// For the dev toolbar
9191
'astro > html-escaper',
92+
'astro/runtime/client/dev-toolbar/entrypoint.js',
9293
],
9394
exclude: ['astro:*', 'virtual:astro:*', 'astro/virtual-modules/prefetch.js'],
9495
// Astro files can't be rendered on the client

0 commit comments

Comments
 (0)