Skip to content

Commit

Permalink
Add support for skipTrailingSlashRedirect and skipMiddlewareUrlNormal…
Browse files Browse the repository at this point in the history
…ize in Turbopack (#56147)

This one only requires the environment variable to be set. Existing
tests already cover this feature.

With these changes `test/e2e/skip-trailing-slash-redirect` can run,
didn't check if there are failing tests yet.

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
timneutkens and kodiakhq[bot] authored Sep 28, 2023
1 parent 711fa21 commit e4d072f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
31 changes: 31 additions & 0 deletions packages/next-swc/crates/next-core/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,37 @@ pub async fn env_for_js(
},
);

map.insert(
"__NEXT_MANUAL_TRAILING_SLASH".to_string(),
if next_config.skip_trailing_slash_redirect.unwrap_or(false) {
"true".to_string()
} else {
"false".to_string()
},
);

map.insert(
"__NEXT_NO_MIDDLEWARE_URL_NORMALIZE".to_string(),
if next_config.skip_middleware_url_normalize.unwrap_or(false) {
"true".to_string()
} else {
"false".to_string()
},
);

map.insert(
"__NEXT_EXTERNAL_MIDDLEWARE_REWRITE_RESOLVE".to_string(),
if next_config
.experimental
.external_middleware_rewrites_resolve
.unwrap_or(false)
{
"true".to_string()
} else {
"false".to_string()
},
);

if !test_mode.is_empty() {
map.insert("__NEXT_TEST_MODE".to_string(), "true".to_string());
}
Expand Down
6 changes: 3 additions & 3 deletions packages/next-swc/crates/next-core/src/next_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ pub struct NextConfig {
pub trailing_slash: Option<bool>,
pub asset_prefix: Option<String>,
pub base_path: Option<String>,
pub skip_middleware_url_normalize: Option<bool>,
pub skip_trailing_slash_redirect: Option<bool>,

///
#[serde(rename = "_originalRedirects")]
Expand Down Expand Up @@ -127,8 +129,6 @@ pub struct NextConfig {
typescript: TypeScriptConfig,
use_file_system_public_routes: bool,
webpack: Option<serde_json::Value>,
skip_middleware_url_normalize: Option<bool>,
skip_trailing_slash_redirect: Option<bool>,
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, TraceRawVcs)]
Expand Down Expand Up @@ -429,6 +429,7 @@ pub struct ExperimentalConfig {
pub swc_plugins: Option<Vec<(String, serde_json::Value)>>,
pub turbo: Option<ExperimentalTurboConfig>,
pub turbotrace: Option<serde_json::Value>,
pub external_middleware_rewrites_resolve: Option<bool>,

// ---
// UNSUPPORTED
Expand All @@ -446,7 +447,6 @@ pub struct ExperimentalConfig {
esm_externals: Option<serde_json::Value>,
extension_alias: Option<serde_json::Value>,
external_dir: Option<bool>,
external_middleware_rewrites_resolve: Option<bool>,
/// If set to `false`, webpack won't fall back to polyfill Node.js modules
/// in the browser Full list of old polyfills is accessible here:
/// [webpack/webpack#Module_notound_error.js#L13-L42](https://github.com/webpack/webpack/blob/2a0536cf510768111a3a6dceeb14cb79b9f59273/lib/Module_not_found_error.js#L13-L42)
Expand Down
3 changes: 3 additions & 0 deletions packages/next/src/lib/turbopack-warning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const supportedTurbopackNextConfigOptions = [
'generateEtags',
'assetPrefix',
'distDir',
'skipMiddlewareUrlNormalize',
'skipTrailingSlashRedirect',
'experimental.externalMiddlewareRewritesResolve',
'experimental.serverComponentsExternalPackages',
'experimental.strictNextHead',
'experimental.turbo',
Expand Down

0 comments on commit e4d072f

Please sign in to comment.