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: rewriting (experimental) #10867

Merged
merged 18 commits into from
May 8, 2024
Merged

feat: rewriting (experimental) #10867

merged 18 commits into from
May 8, 2024

Conversation

ematipico
Copy link
Member

Changes

This is the culmination of the rerouting implementation as experimental.

Here's the RFC: https://github.com/withastro/roadmap/blob/feat/reroute/proposals/0047-rerouting.md

This PR is meant to be merged for v4.8.0.

Testing

Current CI should pass

Docs

cc @withastro/maintainers-docs for feedback!

I will need your help go understand how to document the feature, because this involves Astro pages and middleware.

@ematipico ematipico added this to the 4.8.0 milestone Apr 24, 2024
Copy link

changeset-bot bot commented Apr 24, 2024

🦋 Changeset detected

Latest commit: ff5602a

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 pkg: astro Related to the core `astro` package (scope) pr: docs A PR that includes documentation for review semver: minor Change triggers a `minor` release labels Apr 24, 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 minor changeset. A reviewer will merge this at the next release if approved.

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

Generally this seems to look good to me. Is there anything specific you'd also like review on? As I think the other PRs are already reviewed so we don't need a full review here.

packages/astro/src/core/render-context.ts Outdated Show resolved Hide resolved
@matthewp
Copy link
Contributor

Bikeshedding time! Based on some research I think these are the names various frameworks / server give this feature:

Tool Name Notes
Next.js rewrite Config-level
Sveltekit reroute
Nuxt No support
Remix No support
SolidStart No support
Hono No support
Nginx rewrite
Apache rewrite
Caddy rewrite

@natemoo-re
Copy link
Member

Great context to add @matthewp! +1 to calling this feature rewrite.

@sarah11918
Copy link
Member

sarah11918 commented May 1, 2024

Just leaving a comment in response to @ematipico 's request re: documentation.

UPDATE: Would love to use Ben's #10858 as a model for experimental feature documentation:

  • Show how to enable the experimental flag
  • Provide any config/basic usage instruction right here
  • Link to the RFC for more info and to encourage discussion/get feedback!

While the feature is experimental, and subject to change, it helps keep the spread in docs controlled for where we need to keep constantly updating. It also stops us from writing too much before the feature is fully finalized. (And, every change we make means the translators JUMP on it... so it helps to wait until we're sure!)

BUT (although not my preference): if we REALLY think it's more content than we can reasonably fit in the just experimental domain config, we can add another section to the bottom of the Middleware page as Rerouting (experimental) just like the Internationalization page has domains (experimental) at the end.

And since we do have experimental domains at the end of the internationalization page, we could get away with the i18n-specific usecase of rerouting, linking back to the main entry on rerouting. This wouldn't need to explain anything, just show an example of using the (experimental) rerouting feature to reroute to a different language page content if one page isn't translated.

@ematipico
Copy link
Member Author

Commit 128bbcb (#10867) changes everything to use "rewrite"

@ematipico ematipico changed the title feat: rerouting (experimental) feat: rewriting (experimental) May 6, 2024
Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

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

Thanks @ematipico , the docs part of this is looking great! Just a few suggestions to see what you think!

packages/astro/src/@types/astro.ts Outdated Show resolved Hide resolved
packages/astro/src/@types/astro.ts Show resolved Hide resolved
packages/astro/src/@types/astro.ts Outdated Show resolved Hide resolved
packages/astro/src/@types/astro.ts Show resolved Hide resolved
packages/astro/src/@types/astro.ts Show resolved Hide resolved
@ematipico ematipico requested a review from sarah11918 May 7, 2024 12:20
ematipico and others added 10 commits May 7, 2024 13:20
* chore: implement reroute in dev

* chore: revert naming change

* chore: conditionally create the new request

* chore: handle error

* remove only

* remove only

* chore: add tests and remove logs

* chore: fix regression

* chore: fix regression route matching

* chore: remove unwanted test
* feat: rerouting in ssg

* linting
* feat: implement reroute in dev (#10818)

* chore: implement reroute in dev

* chore: revert naming change

* chore: conditionally create the new request

* chore: handle error

* remove only

* remove only

* chore: add tests and remove logs

* chore: fix regression

* chore: fix regression route matching

* chore: remove unwanted test

* feat: reroute in SSG (#10843)

* feat: rerouting in ssg

* linting

* feat: rerouting in ssg

* linting

* feat: reroute for SSR

* fix rebase

* fix merge issue
* feat: implement reroute in dev (#10818)

* chore: implement reroute in dev

* chore: revert naming change

* chore: conditionally create the new request

* chore: handle error

* remove only

* remove only

* chore: add tests and remove logs

* chore: fix regression

* chore: fix regression route matching

* chore: remove unwanted test

* feat: reroute in SSG (#10843)

* feat: rerouting in ssg

* linting

* feat: rerouting in ssg

* linting

* feat: reroute for SSR

* fix rebase

* fix merge issue

* feat: implement the `next(payload)` feature for rerouting

* chore: revert code

* chore: fix code

* Apply suggestions from code review

Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>

---------

Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
})
```

When enabled, you can use `rewrite()` to **render
Copy link
Member

Choose a reason for hiding this comment

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

Just checking on this formatting here. Did you mean to split up into two lines like this?

Copy link
Contributor

@bholmesdev bholmesdev left a comment

Choose a reason for hiding this comment

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

Left some comments on error messaging and code nits. Overall, this is very well-considered for an experimental release! Appreciate defensive checks like the infinite loop counter as well. You're the re-right man for the job.

packages/astro/src/core/app/pipeline.ts Outdated Show resolved Hide resolved
packages/astro/src/core/build/generate.ts Outdated Show resolved Hide resolved
packages/astro/src/core/build/generate.ts Show resolved Hide resolved
packages/astro/src/core/app/pipeline.ts Outdated Show resolved Hide resolved
packages/astro/src/core/app/pipeline.ts Outdated Show resolved Hide resolved
packages/astro/src/core/render-context.ts Outdated Show resolved Hide resolved
packages/astro/src/vite-plugin-astro-server/pipeline.ts Outdated Show resolved Hide resolved
packages/astro/src/vite-plugin-astro-server/pipeline.ts Outdated Show resolved Hide resolved
packages/astro/src/vite-plugin-astro-server/pipeline.ts Outdated Show resolved Hide resolved
ematipico and others added 3 commits May 7, 2024 16:14
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Co-authored-by:  Matthew Phillips <matthew@skypack.dev>
Co-authored-by: Ben Holmes <hey@bholmes.dev>
Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

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

Left one tiny suggestion for the first line of the changeset, otherwise now approving for docs! 🥳

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
@ematipico ematipico merged commit 47877a7 into main May 8, 2024
14 checks passed
@ematipico ematipico deleted the feat/reroute branch May 8, 2024 09:26
@astrobot-houston astrobot-houston mentioned this pull request May 8, 2024
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) pr: docs A PR that includes documentation for review semver: minor Change triggers a `minor` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants