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

Redirect to 404 when fetching src files on dev server #13094

Closed
1 task
rotate-mark opened this issue Jan 30, 2025 · 3 comments · Fixed by #13095
Closed
1 task

Redirect to 404 when fetching src files on dev server #13094

rotate-mark opened this issue Jan 30, 2025 · 3 comments · Fixed by #13095
Labels
needs triage Issue needs to be triaged

Comments

@rotate-mark
Copy link
Contributor

rotate-mark commented Jan 30, 2025

Astro Info

Astro                    v5.2.0
Node                     v18.20.3
System                   Linux (x64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/node
Integrations             @astrojs/alpinejs

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

No response

Describe the Bug

The dev server redirects the src files request and causes a vite internal server error after upgrading to Astro v5.2.0.

// Without the trailingSlash config, src file requests redirect to 404.
Image

// When trailingSlash is set to 'always', requests to @vite/client return 404.
Image
Image

What's the expected result?

Return 200 and it would not break the page on dev server.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-4nxjmnm3?file=astro.config.mjs

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 Jan 30, 2025
@rotate-mark rotate-mark changed the title Redirect to 404 when fetching files on dev server Redirect to 404 when fetching src files on dev server Jan 30, 2025
@druettiger
Copy link

I can reproduce the issue in Astro 5.2.0:

  1. Create a new Astro project
  2. Set trailingSlash: 'always'
  3. Run npm run dev

Result:

  • Site preview not updating on file changes
  • Astro dev toolbar not loading

@ascorbic
Copy link
Contributor

Thanks. I have a fix #13095

@rotate-mark
Copy link
Contributor Author

rotate-mark commented Jan 30, 2025

@ascorbic Thanks for the quick fix. However, the issue still exists as the srcDir files goes with double slashes path.

Image

The collapseDuplicateTrailingSlashes function should exclude those paths as well.

// @astrojs/internal-helpers/path.js

function collapseDuplicateTrailingSlashes(path, trailingSlash) {
  if (!path) {
    return path;
  }

  if (path.startsWith('/@') || path.startsWith('/_')) {
    return path;
  }

  return path.replace(MANY_TRAILING_SLASHES, trailingSlash ? "/" : "") || "/";
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants