Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't have any routes that start with index. in subpaths #12675

Open
1 task done
ericswpark opened this issue Dec 7, 2024 · 11 comments · May be fixed by #12815
Open
1 task done

Can't have any routes that start with index. in subpaths #12675

ericswpark opened this issue Dec 7, 2024 · 11 comments · May be fixed by #12815
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: routing Related to Astro routing (scope)

Comments

@ericswpark
Copy link

ericswpark commented Dec 7, 2024

Astro Info

Astro                    v5.1.1
Node                     v23.5.0
System                   Windows (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @astrojs/mdx
                         @astrojs/tailwind

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

No response

Describe the Bug

Given the following pages/ directory:

pages/
  blog/
    index.astro
    index.xml.ts

Navigating to blog/ will work (use index.astro), but navigating to blog/index.xml will result in a 404.

What's the expected result?

index* files should map to other routes.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-99jtakub

stackblitz.com/edit/github-99jtakub-y6r7uocq

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Dec 7, 2024
@matthewp
Copy link
Contributor

If you remove index.astro does it work? You can't have two routes that match and expect them both to work.

@matthewp matthewp added needs response Issue needs response from OP and removed needs triage Issue needs to be triaged labels Dec 10, 2024
@ericswpark
Copy link
Author

ericswpark commented Dec 18, 2024

@matthewp unfortunately it does not. I renamed index.astro to a different name. Now, I can't access neither blog/ nor blog/index.xml with the following directory:

pages/
  blog/
    demo.astro
    index.xml.ts

Both links 404.

Sorry for the late response, very busy week.

@ericswpark
Copy link
Author

Just commenting as a soft bump and to confirm that this bug persists in the latest Astro v5. I migrated the migration repo that I am currently working on to v5.1.1 and have encountered the same issue. Will update OP to reflect this and to document the new test environment I am running the repo in.

I'd appreciate it if someone can look into this as I cannot migrate to Astro if it will break existing links.

@ematipico
Copy link
Member

@ericswpark I opened your reproduction, and it seems the issue is happening during be astro preview command, after building the project. Can you confirm?

@ericswpark
Copy link
Author

@ematipico this happens with both astro preview and the dev server (astro dev).

It seems like Astro, or some component of Astro, specially treats all files that start with index.. So for example, inde and indexl will correctly resolve, but index.l will not.

@ematipico
Copy link
Member

I am not sure if your reproduction is the same as your project, but you're returning a new Response() that has no body.

Because of that, Astro doesn't create any file. I would argue that there's a bug where Astro creates a misleading log, but maybe this isn't your bug?

@ericswpark
Copy link
Author

@ematipico sorry, the reproduction might not exactly be the same. In my blog, the index.xml.ts file consists of the following content:

import { experimental_AstroContainer as AstroContainer } from "astro/container";
import { getContainerRenderer as getMDXRenderer } from "@astrojs/mdx";
import { loadRenderers } from "astro:container";
import { render } from "astro:content";

import { getLocaleCollection } from "@/i18n/utilities";

import { getRssString } from '@astrojs/rss';

export async function GET(context: any) {
  const renderers = await loadRenderers([getMDXRenderer()]);
  const container = await AstroContainer.create({ renderers });
  const blogEntries = await getLocaleCollection("en", "blog");

  const items = [];
  for (const post of blogEntries.reverse()) {
    const { Content } = await render(post);
    const content = await container.renderToString(Content);
    const link = `/blog/${post.id.slice(0, -2)}`;
    items.push({
      title: post.data.title,
      pubDate: post.data.date,
      link,
      content,
    });
  }

  const rssString = await getRssString({
    title: "Eric Park's Blog",
    description: "Eric Park's blog posts",
    site: `${context.site}/blog`,
    items,
    customData: `<language>en</language>`,
  });

  return new Response(rssString, {
    headers: {
      "Content-Type": "application/xml",
    },
  });
}

Even when the Response() is not empty like the above, however, Astro just won't include a index.xml file when running npm run build:

image

This is what my source looks like pre-build:

image

As you can see, Astro just ignores the index.xml.ts file altogether and won't include it in the final build.

@ematipico
Copy link
Member

ematipico commented Dec 23, 2024

Please, update the reproduction. We need a way to reproduce the bug 😅

@ematipico ematipico added the needs repro Issue needs a reproduction label Dec 23, 2024
Copy link
Contributor

Hello @ericswpark. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs repro will be closed if they have no activity within 3 days.

@ematipico
Copy link
Member

I changed the reproduction to return a valid response, and I can see the files correctly emitted:

drwxrwxr-x     - ema  23 Dec 11:09  ├──  dist
.rw-rw-r--   749 ema  23 Dec 11:09  │   ├──  favicon.svg
.rw-r--r--   279 ema  23 Dec 11:09  │   ├──  index.html
.rw-r--r--    11 ema  23 Dec 11:09  │   └──  index.xml

@ematipico ematipico closed this as not planned Won't fix, can't repro, duplicate, stale Dec 23, 2024
@ericswpark
Copy link
Author

ericswpark commented Dec 23, 2024

@ematipico please re-open. I was confused too for a second because StackBlitz was putting out index.xml, and I was confused why it wasn't working for my project.

It turns out that this breaks for subpaths. Please see this link:

https://stackblitz.com/edit/github-99jtakub-y6r7uocq

I've updated the issue title. Sorry for the confusion -- I didn't realize it had different behavior for root and subpath 😅 I can confirm the StackBlitz URL above has the correct repro as index.xml will not render at all under subpath.

@ericswpark ericswpark changed the title Can't have any routes that start with index Can't have any routes that start with index. in subpaths Dec 23, 2024
@ematipico ematipico reopened this Dec 23, 2024
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Dec 23, 2024
@ematipico ematipico added - P3: minor bug An edge case that only affects very specific usage (priority) feat: routing Related to Astro routing (scope) and removed needs response Issue needs response from OP needs repro Issue needs a reproduction needs triage Issue needs to be triaged labels Dec 23, 2024
ericswpark added a commit to ericswpark/astro that referenced this issue Dec 23, 2024
The previous code would cause file names like `index.xml.ts` to be
treated as index files, when they aren't (the file basename excluding
the extension `.ts` is `index.xml`, and `index` should be the index
file). To match index files only, match the entire first half of the
basename when splitting by the last occurrence of the period/file
extension delimiter.

Pedantically this might not be correct -- i.e. some file extensions
actually span multiple delimiters, like index.tar.gz. But in that case
it's not an index file as well, so I think this is fine.

Fixes withastro#12675
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: routing Related to Astro routing (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants