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

feat(routing): decode pathname early, don't decode params #12079

Merged
merged 6 commits into from
Oct 2, 2024

Conversation

ematipico
Copy link
Member

@ematipico ematipico commented Sep 26, 2024

Changes

Closes #8516

To partially fix the issue, we had to change some assumptions and expectations about how params are handled.

params aren't decoded anymore, which means that users need to decode the parameters if they need to. While this change might break some users code, it allows us to have better predictability for SSG and SSR.

Changes:

  • RenderContext.pathname is decoded early. Usually, browsers and runtimes encode the URLs when creating a Request object, which means that we need to decode them back, so they match the file system paths that we have in RouteData.
  • The static build is now able to emit files such as [page]/index.html.
  • The function that cleanups the files use paths instead of URL constructs. That was needed because URL does encoding, which is what we want, because now when loading files like [page]/index.html, it will be encoded to something that can't be mapped to the FS file.
  • When generating files, we encode the paths.

Testing

Added new tests.

Please let me know if there are more tests I need to add to prevent future regressions.

Docs

withastro/docs#9497

Copy link

changeset-bot bot commented Sep 26, 2024

🦋 Changeset detected

Latest commit: 53ecdf5

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 Sep 26, 2024
@ematipico ematipico changed the title feat(routing): decode pathname early feat(routing): encode pathname early, don't encode params Sep 26, 2024
@github-actions github-actions bot added the semver: major Change triggers a `major` release label Sep 26, 2024
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

This PR is blocked because it contains a major changeset. A reviewer will merge this at the next release if approved.

@ematipico ematipico changed the title feat(routing): encode pathname early, don't encode params feat(routing): encode pathname early, don't decode params Sep 26, 2024
@ematipico ematipico force-pushed the feat/predictable-encoding-decoding branch from 6039117 to 3c9b5cc Compare September 26, 2024 12:42
@ematipico ematipico changed the title feat(routing): encode pathname early, don't decode params feat(routing): decode pathname early, don't decode params Sep 26, 2024
@ematipico ematipico marked this pull request as ready for review September 26, 2024 13:12
packages/astro/src/core/build/generate.ts Outdated Show resolved Hide resolved
packages/astro/src/core/fs/index.ts Outdated Show resolved Hide resolved
.changeset/wet-foxes-walk.md Outdated Show resolved Hide resolved
@ematipico ematipico merged commit 7febf1f into next Oct 2, 2024
13 checks passed
@ematipico ematipico deleted the feat/predictable-encoding-decoding branch October 2, 2024 11:06
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) semver: major Change triggers a `major` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants