fix(cloudflare): add namespace filter to astro-frontmatter-scan esbuild plugin#16272
fix(cloudflare): add namespace filter to astro-frontmatter-scan esbuild plugin#16272barry3406 wants to merge 5 commits intowithastro:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 80e3e01 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Hey @ematipico, could you take a peek at this when you get a chance? It's a small fix for a Cloudflare adapter regression where |
|
Hi! Could you please add a changeset and some tests to verify the fix? |
Adds a unit test for `astroFrontmatterScanPlugin` that asserts the plugin only registers `onLoad` handlers scoped to the `file` namespace, plus behavioural tests for frontmatter extraction, empty-frontmatter fallback, and the top-level `return` -> `throw` rewrite. The first case is a regression guard for the cross-namespace bug fixed in this PR. Also adds a changeset for `@astrojs/cloudflare`.
|
Hey @rururux — done! Pushed:
I verified the regression assertion fails when the |
| '@astrojs/cloudflare': patch | ||
| --- | ||
|
|
||
| Fixes a Cloudflare adapter regression where importing an `.astro` component as a default export from a `.ts` file failed with `No matching export in "html:..." for import "default"`. The internal `astro-frontmatter-scan` esbuild plugin now scopes its `onLoad` handler to the `file` namespace, so `.astro` files resolved into Vite's `html` namespace fall through to Vite's built-in handler instead of being intercepted by the frontmatter-only loader. |
There was a problem hiding this comment.
Thanks for adding the changeset!
It looks a bit technical, so could you please make it more concise?
You can refer to this link for some guidance: https://contribute.docs.astro.build/docs-for-code-changes/changesets/
|
Done — shortened the changeset to one user-facing line per the docs guide. Thanks! |
7a5b50e to
1bc8d2d
Compare
|
Thanks @rururux — read the changesets guide properly this time and force-pushed a revised version that drops the implementation note and follows the lived |
|
Thanks! The changeset looks good now. |
|
Thanks @rururux — converted to an integration test in The test captures the Astro logger output and asserts that neither I verified the regression actually fires: with |
39ae94b to
f32ce4f
Compare
Per review feedback. The unit test only asserted that the plugin registers `namespace: 'file'`; it never verified that the "No matching export in 'html:...' for import 'default'" error from withastro#16203 actually disappears. The new fixture mirrors the issue reproduction: a `lib/ui.ts` registry default-imports `Inner.astro` and `Outer.astro` (Outer wraps Inner), consumed by a page. The test runs a build through `loadFixture` and captures the Astro logger output, asserting that neither the "No matching export" line nor "Failed to run dependency scan" appears. Removing `namespace: 'file'` makes both assertions fire with the exact error message from withastro#16203.
f32ce4f to
80e3e01
Compare
Fixes #16203
Problem
The
astro-frontmatter-scanesbuild plugin registers itsonLoadhandler without anamespacefilter. In esbuild, an unfilteredonLoadmatches all namespaces, includinghtml. When a.tsfile default-imports an.astrocomponent, Vite's dep scanner resolves the.astrofile into thehtmlnamespace. The plugin intercepts it and returns only the extracted frontmatter — which has noexport default— causing:Fix
Add
namespace: 'file'to theonLoadcall so the plugin only handles.astrofiles resolved from the filesystem. Files in thehtmlnamespace now fall through to Vite's built-inhtmlTypeOnLoadCallback, which already appendsexport default {}for non-.vuefiles.Test plan
filenamespace behavior is unchanged — same handler, same logic, only the namespace scope is narrowed