Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/strip-toolbar-sourcemap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes a spurious 404 request for a dev toolbar sourcemap during `astro dev` caused by the browser mis-resolving a relative `sourceMappingURL` from the `/@id/` URL prefix
28 changes: 28 additions & 0 deletions packages/astro/src/toolbar/vite-plugin-dev-toolbar.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { readFileSync, writeFileSync } from 'node:fs';
import type * as vite from 'vite';
import { telemetry } from '../events/index.js';
import { eventAppToggled } from '../events/toolbar.js';
Expand All @@ -21,6 +22,33 @@ export default function astroDevToolbar({ settings, logger }: AstroPluginOptions
'astro > axobject-query',
...(settings.devToolbarApps.length > 0 ? ['astro/toolbar'] : []),
],
esbuildOptions: {
plugins: [
{
name: 'astro:strip-toolbar-sourcemap',
setup(build) {
// The dev toolbar entrypoint is served via /@id/ which causes
// the browser to mis-resolve the relative sourceMappingURL that
// esbuild adds, producing a bogus 404 request. Strip it after
// esbuild writes the optimized deps to disk.
build.onEnd((result) => {
if (!result.metafile) return;
for (const outputPath of Object.keys(result.metafile.outputs)) {
if (!outputPath.includes('entrypoint') || !outputPath.endsWith('.js')) continue;
const code = readFileSync(outputPath, 'utf-8');
const stripped = code.replace(
/\/\/# sourceMappingURL=.*$/m,
'',
);
if (stripped !== code) {
writeFileSync(outputPath, stripped);
}
}
});
},
},
],
},
},
};
},
Expand Down
Loading