diff --git a/.changeset/toolbar-client-optimize-deps.md b/.changeset/toolbar-client-optimize-deps.md new file mode 100644 index 000000000000..f5e9a148675f --- /dev/null +++ b/.changeset/toolbar-client-optimize-deps.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes an unnecessary full page reload on first navigation during dev diff --git a/packages/astro/src/runtime/client/dev-toolbar/apps/audit/index.ts b/packages/astro/src/runtime/client/dev-toolbar/apps/audit/index.ts index e2a2f16d9c78..e7eb7fdf90e4 100644 --- a/packages/astro/src/runtime/client/dev-toolbar/apps/audit/index.ts +++ b/packages/astro/src/runtime/client/dev-toolbar/apps/audit/index.ts @@ -194,10 +194,13 @@ export default { return; } - // If the element is an image but not yet loaded, ignore it - // TODO: We shouldn't ignore this, because it is valid for an image to not be loaded at start (e.g. lazy loading) + // If the element is an image that hasn't loaded yet, wait for it so that + // position-based checks (e.g. above/below the fold) have accurate layout data. if (originalElement.nodeName === 'IMG' && !(originalElement as HTMLImageElement).complete) { - return; + await new Promise((resolve) => { + originalElement.addEventListener('load', () => resolve(), { once: true }); + originalElement.addEventListener('error', () => resolve(), { once: true }); + }); } audits.push({ diff --git a/packages/astro/src/vite-plugin-environment/index.ts b/packages/astro/src/vite-plugin-environment/index.ts index d2002a5e6de0..b7e2f35ea4cd 100644 --- a/packages/astro/src/vite-plugin-environment/index.ts +++ b/packages/astro/src/vite-plugin-environment/index.ts @@ -89,6 +89,7 @@ export function vitePluginEnvironment({ include: [ // For the dev toolbar 'astro > html-escaper', + 'astro/runtime/client/dev-toolbar/entrypoint.js', ], exclude: ['astro:*', 'virtual:astro:*', 'astro/virtual-modules/prefetch.js'], // Astro files can't be rendered on the client