Skip to content

Conversation

@leonace924
Copy link
Contributor

@leonace924 leonace924 commented Jan 7, 2026

Fixes #15095

Changes

  • What does this change?

Updated baseMiddleware to ensure that after stripping the base path, the resulting URL always starts with / when it's not empty. This preserves query parameters and ensures proper URL parsing downstream.

After:

let newUrl = url.replace(devRoot, devRootReplacement);
// Ensure the URL is a valid path (e.g., /base?foo=bar -> /?foo=bar, not ?foo=bar)
if (newUrl !== '' && !newUrl.startsWith('/')) {
    newUrl = '/' + newUrl;
}
req.url = newUrl;
  • packages/astro/src/vite-plugin-astro-server/base.ts: Added logic to prepend / when the stripped URL doesn't start with / and isn't empty
  • packages/astro/src/vite-plugin-astro-server/request.ts: Already had normalization logic that handles the empty string pathname case (no changes needed)
  • packages/astro/test/units/routing/trailing-slash.test.js: Test already exists for this scenario (issue Query params trigger 404 error in dev #15095)

Testing

The fix ensures that:

  1. /base?query=test → strips to /?query=test → normalizes to empty string pathname for route matching ✅
  2. /base → strips to empty string → normalizes correctly ✅
  3. /base/ → strips to / → normalizes correctly ✅
  • tested with minimal example
{01D2EAEA-075C-46BD-A5E4-D6BE4694A946} {BEBBE330-54BE-4976-950F-B6ECB59B73BC} {2D884BBA-C1FE-490C-BCC6-467CE5C35C21}

Docs

Contribution by Gittensor, see my contribution statistics at https://gittensor.io/miners/details?githubId=42954461

@changeset-bot
Copy link

changeset-bot bot commented Jan 7, 2026

🦋 Changeset detected

Latest commit: 9926b6b

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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jan 7, 2026
@leonace924
Copy link
Contributor Author

@florian-lefebvre can you review my PR? please give me feedback
Thank you for your time

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 7, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing leonace924:fix/trailing-slash (9926b6b) with main (4eb6fc9)1

Summary

✅ 6 untouched benchmarks

Footnotes

  1. No successful run was found on main (8695285) during the generation of this report, so 4eb6fc9 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@florian-lefebvre
Copy link
Member

Hi, some tests are not passing. Can you fix them first?

@leonace924 leonace924 force-pushed the fix/trailing-slash branch 2 times, most recently from df5043d to 9aa7899 Compare January 7, 2026 22:48
@leonace924
Copy link
Contributor Author

leonace924 commented Jan 8, 2026

@florian-lefebvre I’ve added the test screenshot; please review it again.
All tests have passed.
Thank you for your time.

leonace924 and others added 6 commits January 8, 2026 08:51
Fixes issue where requests to /base?query=test would return 404 when
trailingSlash is set to 'never' or 'always'. The baseMiddleware now
ensures URLs always start with '/' after stripping the base path,
preserving query parameters for proper route matching.

Fixes withastro#15095
@leonace924
Copy link
Contributor Author

Hi @florian-lefebvre would you review once more?
I noticed this test error is not related to my changes...
{B1A9B721-ED47-4D65-9B52-09632B8A2D2D}

Copy link
Member

@florian-lefebvre florian-lefebvre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are flaky, nothing to worry about. Thank you!

@florian-lefebvre florian-lefebvre merged commit 81db3c0 into withastro:main Jan 8, 2026
24 of 26 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Jan 8, 2026
matthewp added a commit that referenced this pull request Jan 12, 2026
matthewp added a commit that referenced this pull request Jan 12, 2026
* fix(ci): Reinstall deps after having published VS Code (#14996)

* fix(svelte): allow client directives (#15004)

* fix(assets): Fixes missing format option for svgs in the passthrough service (#14987)

* fix(assets): Fixes missing format option for svgs in the passthrough service

* fix: wtf is going on

* chore: changeset

* [ci] format

* chore: auto format next (#15009)

* chore(deps): update github-actions (#15019)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update all non-major dependencies (#15020)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Support extending the image API props type (#15014)

* [ci] release (#14997)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix(content-layer): Try a smarter solution to normalize bare image paths in JSON (#15028)

* fix(content-layer): Try a smarter solution to normalize bare image paths in JSON

* chore: changeset

* [ci] format

* chore: document core/infra architecture (#14815)

Co-authored-by: Emanuele Stoppa <[email protected]>
Co-authored-by: Matt Kane <[email protected]>
Co-authored-by:  Matthew Phillips <[email protected]>
Co-authored-by: Matthew Phillips <[email protected]>

* [ci] format

* fix(astro): assets vite build log (#15034)

* chore(sitemap): migrate to astro:routes:resolved (#15033)

* fix: Remote images: Prevent internal caching from interfering with Astro's cache (#14954)

Co-authored-by: Florian Lefebvre <[email protected]>

* [ci] format

* Update font utility dependencies to use lighter versions (#15055)

* Update font utility dependencies to use lighter versions

* Add changeset

* skip flaky view transitions redirect test (#15060)

* chore(deps): update actions-cool/issues-helper action to v3.7.5 (#15071)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* ClientRouter: Preserve hash fragment during redirects (#15088)

* try resurrecting a flaky test (#15089)

* fix(deps): update astro adapters (#15084)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update all non-major dependencies (#15072)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(deps): update astro client runtimes (#15085)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix: move ts-plugin node_modules to dist (#15083)

* fix: move ts-plugin node_modules to dist

* add: changeset

* [ci] format

* Update image-size (#15105)

* fix: components imports paths (#15107)

* Tailwind example, README.md: update link (#15099)

* fix(assets): Use Vite's isFileLoadingAllowed to check if a file can be loaded (#15052)

* fix(assets): Use Vite's isFileLoadingAllowed to check if a file can be loaded

* test: add

* fix: windwos perhaos?

* chore: changeset

* [ci] format

* Update prettier extension to new one (#15108)

* fix(vscode): Correctly handle TypeScript blocks ending with types (#15109)

* fix(vscode): Correctly handle TypeScript blocks ending with types

* chore: changeset

* [ci] format

* fix(svelte): improve Svelte children prop type checking (#15070)

* chore: Replace fast-glob with tinyglobby in language server (#15057)

* chore: Replace fast-glob with tinyglobby in language server

* Use `expandDirectories` option for compatibility with fast-glob

* Update packages/language-tools/language-server/src/check.ts

---------

Co-authored-by: Erika <[email protected]>

* view transitions: fix Firefox e2e tests for playwright 1.57 (#15113)

* fix(deps): update astro dependencies (#15103)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Florian Lefebvre <[email protected]>

* fix: lint vt test (#15114)

* [ci] format

* fix(deps): update language tools (#15104)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Florian Lefebvre <[email protected]>

* Feature/allow node 24 vercel adapter (#15116)

* feat(fonts): new font resolver abstraction (#15111)

* [ci] format

* feat(fonts)!: upgrade unifont and support formats (#15117)

Co-authored-by: Sarah Rainsberger <[email protected]>

* fix(vue): add HTML attributes to generated TypeScript types (#15016)

* fix(vue): add HTML attributes to generated TypeScript types

Fixes #14686

* fix: add package exports and update tests for HTML attributes support

* test(vue): add astro check test for HTML attributes

Add test fixture and test case to verify that Vue components
correctly accept HTML attributes (class, style, id, data-*) and
client directives via astro check.

Follows the same pattern as the Svelte integration tests.

* chore: update lockfile for vue prop-types fixture

* feat: deduplicate context types (#15122)

Co-authored-by: Armand Philippot <[email protected]>

* perf(astro): group chunks on emit (#15123)

Co-authored-by: Florian Lefebvre <[email protected]>


Co-authored-by: matthewp <[email protected]>
Co-authored-by: florian-lefebvre <[email protected]>
Co-authored-by: ematipico <[email protected]>

* feat(fonts): clean types (#15118)

* [ci] release (#15031)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix(vscode): Don't update @types/vscode automatically (#15131)

* fix(vscode): Don't update @types/vscode automatically

* chore: changeset

* fix: adjust page warning to only show up in more relevant times (#15127)

* fix: adjust page warning to only show up in more relevant times

* chore: changeset

* [ci] format

* Update security contacts list (#15143)

* fix(dev): preserve query params when base path is stripped (#15124)

Co-authored-by: Florian Lefebvre <[email protected]>

* fix(assets): hoist ?? inside JSON.stringify in virtual module codegen (#15140)

* fix(assets): hoist nullish coalescing inside JSON.stringify

Moves ?? fallbacks before serialization to eliminate dead code in
generated virtual module. Fixes esbuild suspicious-nullish-coalescing
warning.

* chore: add changeset

* Attempt to reduce falkiness in view transition e2e tests (#15142)

* Attempt to reduce falkiness in view transition e2e tests

* try wait for idle state

* next try

* Update view-transitions.test.js

* [ci] format

* fix(toolbar): skip image audit for framework components (#15149)

* fix(toolbar): skip image audit for framework components

Images inside astro-island elements (React, Vue, Svelte, etc. with client:* directives) now skip the 'Use the Image component' audit warning, since these components can't directly use Astro's Image component.

Fixes #15048

* test: remove unused image

* test: use smaller test image (22KB instead of 253KB)

* fix: Accept setCookie from both context and headers (#15152)

Co-authored-by: Florian Lefebvre <[email protected]>

* [ci] release (#15132)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix(ci): Move ts-plugin-bundle to node_modules after recreating node_modules (#15156)

* fix(ci): Move ts-plugin-bundle to node_modules after recreating node_modules

* fix: make itw ork in dev

* chore: changeset

* [ci] release (#15158)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: scripts not rendering with unused Fragment slots (#13847) (#15147)

* Fix hydration for framework components in MDX slots (#15150)

* Fix hydration for framework components in MDX slots using Astro.slots.render()

* Update packages/astro/src/runtime/server/render/slot.ts

Co-authored-by: Luiz Ferraz <[email protected]>

---------

Co-authored-by: Luiz Ferraz <[email protected]>

* [ci] format

* Fixes build

* fix: apply trailing slash query params fix to new architecture

Port fix from #15124 to vite-plugin-app/app.ts

---------

Co-authored-by: Erika <[email protected]>
Co-authored-by: Antony Faris <[email protected]>
Co-authored-by: Erika <[email protected]>
Co-authored-by: Florian Lefebvre <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Chris Swithinbank <[email protected]>
Co-authored-by: Houston (Bot) <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Emanuele Stoppa <[email protected]>
Co-authored-by: Matt Kane <[email protected]>
Co-authored-by: Florian Lefebvre <[email protected]>
Co-authored-by: Volpeon <[email protected]>
Co-authored-by: Martin Trapp <[email protected]>
Co-authored-by: fkatsuhiro <[email protected]>
Co-authored-by: Oliver Speir <[email protected]>
Co-authored-by: Andreas Deininger <[email protected]>
Co-authored-by: Roman <[email protected]>
Co-authored-by: fabon <[email protected]>
Co-authored-by: Raanelom <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Rahul Dogra <[email protected]>
Co-authored-by: Armand Philippot <[email protected]>
Co-authored-by: James Garbutt <[email protected]>
Co-authored-by: matthewp <[email protected]>
Co-authored-by: florian-lefebvre <[email protected]>
Co-authored-by: ematipico <[email protected]>
Co-authored-by: Pegasus <[email protected]>
Co-authored-by: Cameron Smith <[email protected]>
Co-authored-by: Martin Trapp <[email protected]>
Co-authored-by: Rafael ヤスヒデ 須藤 <[email protected]>
Co-authored-by: Luiz Ferraz <[email protected]>
dadezzz pushed a commit to dadezzz/ice-notes that referenced this pull request Jan 13, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [astro](https://astro.build) ([source](https://github.com/withastro/astro/tree/HEAD/packages/astro)) | [`5.16.7` → `5.16.8`](https://renovatebot.com/diffs/npm/astro/5.16.7/5.16.8) | ![age](https://developer.mend.io/api/mc/badges/age/npm/astro/5.16.8?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/astro/5.16.7/5.16.8?slim=true) |

---

### Release Notes

<details>
<summary>withastro/astro (astro)</summary>

### [`v5.16.8`](https://github.com/withastro/astro/blob/HEAD/packages/astro/CHANGELOG.md#5168)

[Compare Source](https://github.com/withastro/astro/compare/[email protected]@5.16.8)

##### Patch Changes

- [#&#8203;15124](withastro/astro#15124) [`81db3c0`](withastro/astro@81db3c0) Thanks [@&#8203;leonace924](https://github.com/leonace924)! - Fixes an issue where requests with query parameters to the `base` path would return a 404 if trailingSlash was not `'ignore'` in development

- [#&#8203;15152](withastro/astro#15152) [`39ee41f`](withastro/astro@39ee41f) Thanks [@&#8203;rururux](https://github.com/rururux)! - Fixes a case where `context.cookies.set()` would be overriden when setting cookies via response headers in development

- [#&#8203;15140](withastro/astro#15140) [`6f6f8f8`](withastro/astro@6f6f8f8) Thanks [@&#8203;cameronraysmith](https://github.com/cameronraysmith)! - Fixes esbuild warning due to dead code in assets virtual module

- [#&#8203;15127](withastro/astro#15127) [`2cff904`](withastro/astro@2cff904) Thanks [@&#8203;Princesseuh](https://github.com/Princesseuh)! - Updates "Unsupported page types found" error to only appear in more realistic cases

- [#&#8203;15149](withastro/astro#15149) [`34f84c2`](withastro/astro@34f84c2) Thanks [@&#8203;rahuld109](https://github.com/rahuld109)! - Skips "Use the Image component" audit warning for images inside framework components (React, Vue, Svelte, etc.)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi43OC4yIiwidXBkYXRlZEluVmVyIjoiNDIuNzguMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Co-authored-by: Renovate Bot <[email protected]>
Co-committed-by: Renovate Bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query params trigger 404 error in dev

2 participants