withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
45.4k stars 2.37k forks source link

Astro renders the file from the project root, not from the contents folder #11267

Open azat-io opened 2 months ago

azat-io commented 2 months ago

Astro Info

Astro                    v4.10.2
Node                     v22.2.0
System                   macOS (arm64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             @playform/compress
                         @astrojs/svelte
                         @astrojs/mdx
                         @astrojs/vue

If this issue only occurs in one browser, which browser is a problem?

Any browser

Describe the Bug

I have a specific project structure. This project is an ESLint plugin.

.
├── rules/
│   └── my-eslint-rule.ts
├── docs/
│   ├── content/
│   │   ├── rules/
│   │   │   └── my-eslint-rule.mdx
│   │   └── config.ts
│   └── pages/
│       └── rules/
│           └── [...slug].ts
└── astro.config.ts

For this reason, I configure srcDir in the Astro config.

However, if the path inside srcDir matches the path in the project root, Astro renders the contents of the TypeScript file in development mode.

I created a project to reproduce the problem: https://stackblitz.com/edit/withastro-astro-bjf3yl?file=posts%2Ftest.ts,astro.config.mjs,docs%2Fpages%2Fposts%2F[...slug].astro

Open project and click "open page" to see the problem.

image

In my example, I expect to see the contents of docs/content/posts/test.md, not the contents of posts/test.ts.

The problem is only reproduced in development mode. And only if the path does not have a trailing slash.

What's the expected result?

I expect Astro to render the contents of the Markdown file, not the TypeScript file, which is not in srcDir at all.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-bjf3yl?file=posts%2Ftest.ts,astro.config.mjs,docs%2Fpages%2Fposts%2F[...slug].astro

Participation

bluwy commented 2 months ago

Seems like one of Vite's middleware is taking a higher priority than Astro's when handling the request, in which Vite will serve the file from the fs as-is, but we should probably takeover and match the routing first.

ascorbic commented 2 months ago

I don't know if something has changed, but I can't reproduce the issue with your Stackblitz. I click on "open page" and it shows "OK". I've downloaded and run it locally and it's the same. This is what I get for both:

image

Could you check the repro and see if it's still happening for you?

azat-io commented 2 months ago

https://github.com/withastro/astro/assets/5698350/37b42cdb-357b-42e8-85f7-510e86cfa8a5

ascorbic commented 2 months ago

Whoa, this is a fun one. I can reproduce it in Chrome but it works fine in Firefox.

bluwy commented 2 months ago

Perhaps Chrome/Firefox is sending additional request headers that affect how the middleware works 🤔

ascorbic commented 2 months ago

I'm having real trouble reproducing this. I can't get reproduce it locally at all, and Stackblitz is really hard to debug network-wise. It seems to be intermittent even in Chrome. It works fine a lot of the time.

ascorbic commented 1 month ago

Are you able to reproduce this anywhere except Stackblitz, because I can't?