Skip to content

docs: clarify Astro.url and Astro.params runtime behavior#13903

Open
Prayaksh wants to merge 3 commits into
withastro:mainfrom
Prayaksh:fix/astro-url-runtime-docs
Open

docs: clarify Astro.url and Astro.params runtime behavior#13903
Prayaksh wants to merge 3 commits into
withastro:mainfrom
Prayaksh:fix/astro-url-runtime-docs

Conversation

@Prayaksh
Copy link
Copy Markdown

Description (required)

This PR clarifies the runtime behavior of URL decoding in Astro v6 dynamic routes.

The original issue was reported in the withastro/astro repository, and after maintainer confirmation it was identified as a documentation gap rather than a runtime bug.

In Astro v6, Astro.url returns a normalized and partially decoded URL, which may differ from new URL(Astro.request.url). Additionally, Astro.params values are automatically decoded. This behavior was not clearly documented in the v6 upgrade guide section covering percent-encoded routes.

This update adds a runtime clarification under the “Percent-Encoding in routes” section to reflect the actual behavior and avoid confusion for users working with encoded dynamic route segments.


Related issues & labels (optional)


@netlify
Copy link
Copy Markdown

netlify Bot commented May 17, 2026

Deploy Preview for astro-docs-2 ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 16481ea
🔍 Latest deploy log https://app.netlify.com/projects/astro-docs-2/deploys/6a1a7bc73e15410008118fc8
😎 Deploy Preview https://deploy-preview-13903--astro-docs-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@astrobot-houston
Copy link
Copy Markdown
Contributor

Hello! Thank you for opening your first PR to Astro’s Docs! 🎉

Here’s what will happen next:

  1. Our GitHub bots will run to check your changes.
    If they spot any broken links you will see some error messages on this PR.
    Don’t hesitate to ask any questions if you’re not sure what these mean!

  2. In a few minutes, you’ll be able to see a preview of your changes on Netlify 🥳.

  3. One or more of our maintainers will take a look and may ask you to make changes.
    We try to be responsive, but don’t worry if this takes a few days.

@astrobot-houston
Copy link
Copy Markdown
Contributor

astrobot-houston commented May 17, 2026

Lunaria Status Overview

🌕 This pull request will trigger status changes.

Learn more

By default, every PR changing files present in the Lunaria configuration's files property will be considered and trigger status changes accordingly.

You can change this by adding one of the keywords present in the ignoreKeywords property in your Lunaria configuration file in the PR's title (ignoring all files) or by including a tracker directive in the merged commit's description.

Tracked Files

File Note
en/guides/upgrade-to/v6.mdx Source changed, localizations will be marked as outdated.
en/reference/api-reference.mdx Source changed, localizations will be marked as outdated.
Warnings reference
Icon Description
🔄️ The source for this localization has been updated since the creation of this pull request, make sure all changes in the source have been applied.

Copy link
Copy Markdown
Member

@ArmandPhilippot ArmandPhilippot left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

If this is indeed a documentation issue (I wouldn't say "probably" means "confirmation"), this addition can be helpful but it doesn't fully fix the issue.

The issue mentions a misleading description in https://docs.astro.build/en/reference/api-reference/#url and potentially in https://docs.astro.build/en/reference/api-reference/#params

@ematipico can you confirm we should fix the docs? Or the fix mentioned by the bot could work and no docs change is required?

Edit: I hadn't followed the linked PR, it seems this might have been fixed in withastro/astro#16808 ?

@ArmandPhilippot ArmandPhilippot added improve or update documentation Enhance / update existing documentation (e.g. add example, improve description, update for changes) should this be documented? Need to figure out whether this is something to add to documentation or not labels May 21, 2026
@Prayaksh
Copy link
Copy Markdown
Author

I realize now that I acted on the “probably” comment before the issue was fully confirmed. Thank you for clarifying. I’m still learning the process and will make sure to verify before updating the docs in the future.

@ematipico
Copy link
Copy Markdown
Member

The documentation update is still valid, because not all characters can be safely decoded e.g. %25AB. Even after my fix, there are still cases that are uncertain, so Astro play it safe and returns an error.

@ArmandPhilippot ArmandPhilippot removed the should this be documented? Need to figure out whether this is something to add to documentation or not label May 22, 2026
@ArmandPhilippot
Copy link
Copy Markdown
Member

Okay, thanks Ema!

And no problem @Prayaksh! Are you still willing to check if other pages require an update? It seems we at least need to update https://docs.astro.build/en/reference/api-reference/#url

@Prayaksh
Copy link
Copy Markdown
Author

Thanks @ArmandPhilippot ! I’ve updated the Astro.url and Astro.params API reference docs to clarify the normalization/decoding behavior as well.

Copy link
Copy Markdown
Member

@ArmandPhilippot ArmandPhilippot left a comment

Choose a reason for hiding this comment

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

Thanks for the update! But, I think the upgrade guide addition is misplaced and your description for Astro.params doesn't seem correct.

Comment thread src/content/docs/en/reference/api-reference.mdx Outdated
Comment thread src/content/docs/en/reference/api-reference.mdx Outdated
Comment thread src/content/docs/en/reference/api-reference.mdx Outdated

`Astro.params` values are automatically decoded, and percent-encoded characters in pathnames or parameters (like `%25`) may appear decoded in `Astro.url` or `Astro.params`.

If you need the raw request URL with no decoding, use `Astro.request.url` and parse it manually.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This doesn't seem to be the right place:

  • In "What should I do?" we explain what the user should do based on the change describe above. Here we are explaining that something else has changed without explaining what the user should do.
  • This is in the "Removed: Percent-Encoding in routes" section... but here we are not explaining something that has been removed but changed. Even, if this is tied to the same PR, it seems doesn't feel right.

I think we need a new section in "Breaking changes" instead. Probably something similar to this one https://docs.astro.build/en/guides/upgrade-to/v5/#changed-params-no-longer-decoded in the v5 upgrade guide.

@Prayaksh
Copy link
Copy Markdown
Author

tried to change as suggested.

thanks!

A normalized [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) object derived from the current `request.url` value. It is useful for interacting with individual properties of the request URL, like pathname and origin.

`Astro.url` is equivalent to doing `new URL(Astro.request.url)`.
Since Astro v6, the pathname is partially decoded during route normalization. This means `Astro.url.pathname` may differ from `new URL(Astro.request.url).pathname` for percent-encoded route segments.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Since Astro v6, the pathname is partially decoded during route normalization. This means `Astro.url.pathname` may differ from `new URL(Astro.request.url).pathname` for percent-encoded route segments.
Since Astro v6, the pathname may be partially decoded during route normalization. This means `Astro.url.pathname` may differ from `new URL(Astro.request.url).pathname` for percent-encoded route segments.

It's not always the case, so maybe using "may" sounds better

Copy link
Copy Markdown
Member

@ArmandPhilippot ArmandPhilippot left a comment

Choose a reason for hiding this comment

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

Thanks for the update but, in addition to Ema suggestion, I see two issues:

  • configuration-reference.mdx contains unrelated changes
  • the upgrade guide section is misplaced:

Comment on lines +835 to +844
## Changed: Route pathname normalization

Since Astro v6, route pathnames are partially decoded during route normalization. This means `Astro.url.pathname` may differ from `new URL(Astro.request.url).pathname` for percent-encoded route segments.

This also affects route params derived from normalized pathnames.

### What should I do?

If you need access to the original encoded pathname, use `new URL(Astro.request.url).pathname` instead of `Astro.url.pathname`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be an h3 (instead of h2) and h4 (instead of h3) and moved to the Breaking changes section.

Comment on lines +520 to +521
When deploying behind reverse proxies or serverless platforms (for example Vercel), configure `allowedDomains` so Astro can safely trust forwarded host headers during origin validation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As stated at the beginning of this file, it is read-only and auto-generated from the main repo. So, any change should be made in the withastro/astro repo instead.
But, anyway, this sounds unrelated to this PR or the issue.

@Prayaksh Prayaksh force-pushed the fix/astro-url-runtime-docs branch from 440fed4 to 16481ea Compare May 30, 2026 05:55
@Prayaksh
Copy link
Copy Markdown
Author

Sorry for the confusion — my previous commit accidentally included an unrelated change. I've corrected the commit and updated the branch so the PR now only contains the intended documentation changes.

I also wasn't able to identify the source PR for this behavior change. If there's a specific PR number that should be referenced, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improve or update documentation Enhance / update existing documentation (e.g. add example, improve description, update for changes)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

URL Decoding in Dynamic Routes (SSR)

4 participants