这是indexloc提供的服务,不要输入任何密码
Skip to content

Handle routing by calling Next.js code #3446

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

Merged
merged 26 commits into from
Jan 26, 2023
Merged

Handle routing by calling Next.js code #3446

merged 26 commits into from
Jan 26, 2023

Conversation

jridgewell
Copy link
Contributor

@jridgewell jridgewell commented Jan 24, 2023

This implements routing by using a-yet-to-be-implemented API exposed by Next.js. The API follows something similar to:

type MakeResolver = (config: NextConfig) => Resolver;
type Resolver = (IncomingMessage, ServerResponse) => Promise<void> | void;

import { makeResolver } from "next/dist/...";
const resolver  = makeResolver(nextConfig as object);

// Later, once we have a request we'd like to route:
// We don't care what the promise resolved to, we just want it to settle.
await resolver(req, res);

The resolver can do 1 of 3 things with this:

  1. Return a redirect response Removed
  2. Return a rewrite response
  3. Stream a middleware response

1. Return a redirect response

First, ensure a x-nextjs-route-result: 1 header is present on the response. Then return a JSON encoded body:

{
  url: string,
  statusCode: u16,
  headers: Record<string, string>
  isRedirect: true
}

The Rust server will then respond with a redirect using to the appropriate location.

  1. Return a rewrite response

First, ensure a x-nextjs-route-result: 1 header is present on the response. Then return a JSON encoded body:

{
  url: string,
  headers: Record<string, string>
}

The Rust server will use this updated URL to request content from our handlers.

  1. Stream a middleware response

Ensure x-nextjs-route-result header is not present on the response. All headers will be sent back, and the body will be streamed back to the browser.


TODO:

  • Do headers actually matter to a redirect Yes?
  • Does statusCode actually matter to a rewrite? No
  • We can't handle streaming body responses yet. Mocked by buffering.

Fixes WEB-228

@jridgewell jridgewell requested review from a team as code owners January 24, 2023 06:58
@vercel
Copy link

vercel bot commented Jan 24, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
examples-basic-web 🔄 Building (Inspect) Jan 26, 2023 at 7:34PM (UTC)
examples-tailwind-web 🔄 Building (Inspect) Jan 26, 2023 at 7:34PM (UTC)
8 Ignored Deployments
Name Status Preview Comments Updated
examples-cra-web ⬜️ Ignored (Inspect) Jan 26, 2023 at 7:34PM (UTC)
examples-designsystem-docs ⬜️ Ignored (Inspect) Jan 26, 2023 at 7:34PM (UTC)
examples-kitchensink-blog ⬜️ Ignored (Inspect) Jan 26, 2023 at 7:34PM (UTC)
examples-native-web ⬜️ Ignored (Inspect) Jan 26, 2023 at 7:34PM (UTC)
examples-nonmonorepo ⬜️ Ignored (Inspect) Jan 26, 2023 at 7:34PM (UTC)
examples-svelte-web ⬜️ Ignored (Inspect) Jan 26, 2023 at 7:34PM (UTC)
examples-vite-web ⬜️ Ignored (Inspect) Jan 26, 2023 at 7:34PM (UTC)
turbo-site ⬜️ Ignored (Inspect) Visit Preview Jan 26, 2023 at 7:34PM (UTC)

@jridgewell jridgewell changed the title Handle routing via calling Next.js code Handle routing by calling Next.js code Jan 24, 2023
@github-actions
Copy link
Contributor

Benchmark for 3e5a870

Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8223.60µs ± 74.90µs 8801.19µs ± 83.98µs +7.02% +3.10%
bench_hmr_to_commit/Turbopack RCC/1000 modules 8524.05µs ± 46.36µs 16.66ms ± 0.35ms +95.39% +85.11%
bench_hmr_to_commit/Turbopack RSC/1000 modules 458.76ms ± 2.94ms 911.23ms ± 5.42ms +98.63% +93.78%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8246.58µs ± 59.05µs 9012.25µs ± 92.41µs +9.28% +5.53%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7155.93µs ± 67.67µs 7890.79µs ± 110.17µs +10.27% +5.20%
bench_hmr_to_eval/Turbopack RCC/1000 modules 7295.46µs ± 97.08µs 12.49ms ± 0.22ms +71.21% +60.84%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7272.89µs ± 67.60µs 8261.07µs ± 95.09µs +13.59% +8.95%
bench_hydration/Turbopack RCC/1000 modules 3313.04ms ± 12.72ms 3543.19ms ± 23.46ms +6.95% +4.73%
bench_hydration/Turbopack RSC/1000 modules 2776.94ms ± 11.12ms 3081.67ms ± 25.20ms +10.97% +8.29%
bench_hydration/Turbopack SSR/1000 modules 2598.00ms ± 10.81ms 2871.06ms ± 15.40ms +10.51% +8.42%
bench_startup/Turbopack CSR/1000 modules 1658.54ms ± 6.05ms 1789.88ms ± 3.47ms +7.92% +6.72%
bench_startup/Turbopack RCC/1000 modules 2483.96ms ± 11.30ms 2635.02ms ± 19.61ms +6.08% +3.56%
bench_startup/Turbopack SSR/1000 modules 2051.32ms ± 9.85ms 2191.87ms ± 6.98ms +6.85% +5.16%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8223.60µs ± 74.90µs 8801.19µs ± 83.98µs +7.02% +3.10%
bench_hmr_to_commit/Turbopack RCC/1000 modules 8524.05µs ± 46.36µs 16.66ms ± 0.35ms +95.39% +85.11%
bench_hmr_to_commit/Turbopack RSC/1000 modules 458.76ms ± 2.94ms 911.23ms ± 5.42ms +98.63% +93.78%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8246.58µs ± 59.05µs 9012.25µs ± 92.41µs +9.28% +5.53%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7155.93µs ± 67.67µs 7890.79µs ± 110.17µs +10.27% +5.20%
bench_hmr_to_eval/Turbopack RCC/1000 modules 7295.46µs ± 97.08µs 12.49ms ± 0.22ms +71.21% +60.84%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7272.89µs ± 67.60µs 8261.07µs ± 95.09µs +13.59% +8.95%
bench_hydration/Turbopack RCC/1000 modules 3313.04ms ± 12.72ms 3543.19ms ± 23.46ms +6.95% +4.73%
bench_hydration/Turbopack RSC/1000 modules 2776.94ms ± 11.12ms 3081.67ms ± 25.20ms +10.97% +8.29%
bench_hydration/Turbopack SSR/1000 modules 2598.00ms ± 10.81ms 2871.06ms ± 15.40ms +10.51% +8.42%
bench_startup/Turbopack CSR/1000 modules 1658.54ms ± 6.05ms 1789.88ms ± 3.47ms +7.92% +6.72%
bench_startup/Turbopack RCC/1000 modules 2483.96ms ± 11.30ms 2635.02ms ± 19.61ms +6.08% +3.56%
bench_startup/Turbopack RSC/1000 modules 2434.20ms ± 12.01ms 2475.82ms ± 13.65ms +1.71%
bench_startup/Turbopack SSR/1000 modules 2051.32ms ± 9.85ms 2191.87ms ± 6.98ms +6.85% +5.16%

@github-actions
Copy link
Contributor

github-actions bot commented Jan 24, 2023

⚠️ CI failed ⚠️

The following steps have failed in CI:

  • Rust tests

See workflow summary for details

@github-actions
Copy link
Contributor

Benchmark for e0b2b1f

Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8176.61µs ± 57.24µs 8656.77µs ± 145.19µs +5.87% +0.91%
bench_hmr_to_commit/Turbopack RCC/1000 modules 8434.07µs ± 55.76µs 8914.55µs ± 53.91µs +5.70% +3.06%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8356.59µs ± 73.95µs 9206.62µs ± 104.05µs +10.17% +5.81%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7264.70µs ± 52.53µs 7854.75µs ± 113.62µs +8.12% +3.50%
bench_hmr_to_eval/Turbopack RCC/1000 modules 7410.23µs ± 37.84µs 7872.28µs ± 117.58µs +6.24% +2.02%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7259.72µs ± 40.50µs 8122.78µs ± 127.51µs +11.89% +7.18%
bench_hydration/Turbopack RCC/1000 modules 3268.98ms ± 7.54ms 3580.34ms ± 12.99ms +9.52% +8.23%
bench_hydration/Turbopack RSC/1000 modules 2739.85ms ± 8.79ms 3007.90ms ± 13.81ms +9.78% +8.08%
bench_hydration/Turbopack SSR/1000 modules 2564.99ms ± 7.75ms 2835.92ms ± 9.52ms +10.56% +9.16%
bench_startup/Turbopack CSR/1000 modules 1612.40ms ± 5.35ms 1775.82ms ± 10.51ms +10.14% +8.11%
bench_startup/Turbopack RCC/1000 modules 2140.84ms ± 6.30ms 2269.50ms ± 9.26ms +6.01% +4.53%
bench_startup/Turbopack RSC/1000 modules 2040.57ms ± 4.86ms 2151.84ms ± 5.19ms +5.45% +4.45%
bench_startup/Turbopack SSR/1000 modules 1715.46ms ± 3.30ms 1830.86ms ± 3.66ms +6.73% +5.89%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8176.61µs ± 57.24µs 8656.77µs ± 145.19µs +5.87% +0.91%
bench_hmr_to_commit/Turbopack RCC/1000 modules 8434.07µs ± 55.76µs 8914.55µs ± 53.91µs +5.70% +3.06%
bench_hmr_to_commit/Turbopack RSC/1000 modules 454.20ms ± 2.60ms 463.71ms ± 2.74ms +2.10%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8356.59µs ± 73.95µs 9206.62µs ± 104.05µs +10.17% +5.81%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7264.70µs ± 52.53µs 7854.75µs ± 113.62µs +8.12% +3.50%
bench_hmr_to_eval/Turbopack RCC/1000 modules 7410.23µs ± 37.84µs 7872.28µs ± 117.58µs +6.24% +2.02%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7259.72µs ± 40.50µs 8122.78µs ± 127.51µs +11.89% +7.18%
bench_hydration/Turbopack RCC/1000 modules 3268.98ms ± 7.54ms 3580.34ms ± 12.99ms +9.52% +8.23%
bench_hydration/Turbopack RSC/1000 modules 2739.85ms ± 8.79ms 3007.90ms ± 13.81ms +9.78% +8.08%
bench_hydration/Turbopack SSR/1000 modules 2564.99ms ± 7.75ms 2835.92ms ± 9.52ms +10.56% +9.16%
bench_startup/Turbopack CSR/1000 modules 1612.40ms ± 5.35ms 1775.82ms ± 10.51ms +10.14% +8.11%
bench_startup/Turbopack RCC/1000 modules 2140.84ms ± 6.30ms 2269.50ms ± 9.26ms +6.01% +4.53%
bench_startup/Turbopack RSC/1000 modules 2040.57ms ± 4.86ms 2151.84ms ± 5.19ms +5.45% +4.45%
bench_startup/Turbopack SSR/1000 modules 1715.46ms ± 3.30ms 1830.86ms ± 3.66ms +6.73% +5.89%

@github-actions
Copy link
Contributor

Benchmark for b4413a0

Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8244.78µs ± 48.97µs 8948.43µs ± 90.99µs +8.53% +5.08%
bench_hmr_to_commit/Turbopack RCC/1000 modules 8546.44µs ± 91.02µs 8991.31µs ± 67.80µs +5.21% +1.46%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8293.24µs ± 54.27µs 8920.41µs ± 119.73µs +7.56% +3.32%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7189.82µs ± 41.62µs 8241.79µs ± 50.01µs +14.63% +11.94%
bench_hmr_to_eval/Turbopack RCC/1000 modules 7484.26µs ± 49.53µs 7954.23µs ± 65.06µs +6.28% +3.18%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7376.40µs ± 46.44µs 7977.61µs ± 112.06µs +8.15% +3.80%
bench_hydration/Turbopack RCC/1000 modules 3279.42ms ± 13.03ms 3696.18ms ± 13.25ms +12.71% +11.02%
bench_hydration/Turbopack RSC/1000 modules 2736.77ms ± 7.91ms 3140.18ms ± 16.10ms +14.74% +12.91%
bench_hydration/Turbopack SSR/1000 modules 2580.35ms ± 10.53ms 2966.18ms ± 17.34ms +14.95% +12.69%
bench_startup/Turbopack CSR/1000 modules 1608.74ms ± 3.87ms 1995.92ms ± 11.71ms +24.07% +22.02%
bench_startup/Turbopack RCC/1000 modules 2128.35ms ± 4.91ms 2361.75ms ± 5.75ms +10.97% +9.92%
bench_startup/Turbopack RSC/1000 modules 2045.09ms ± 4.42ms 2279.06ms ± 7.45ms +11.44% +10.24%
bench_startup/Turbopack SSR/1000 modules 1728.56ms ± 4.36ms 1958.77ms ± 1.90ms +13.32% +12.53%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8244.78µs ± 48.97µs 8948.43µs ± 90.99µs +8.53% +5.08%
bench_hmr_to_commit/Turbopack RCC/1000 modules 8546.44µs ± 91.02µs 8991.31µs ± 67.80µs +5.21% +1.46%
bench_hmr_to_commit/Turbopack RSC/1000 modules 449.62ms ± 3.29ms 454.91ms ± 3.04ms +1.18%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8293.24µs ± 54.27µs 8920.41µs ± 119.73µs +7.56% +3.32%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7189.82µs ± 41.62µs 8241.79µs ± 50.01µs +14.63% +11.94%
bench_hmr_to_eval/Turbopack RCC/1000 modules 7484.26µs ± 49.53µs 7954.23µs ± 65.06µs +6.28% +3.18%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7376.40µs ± 46.44µs 7977.61µs ± 112.06µs +8.15% +3.80%
bench_hydration/Turbopack RCC/1000 modules 3279.42ms ± 13.03ms 3696.18ms ± 13.25ms +12.71% +11.02%
bench_hydration/Turbopack RSC/1000 modules 2736.77ms ± 7.91ms 3140.18ms ± 16.10ms +14.74% +12.91%
bench_hydration/Turbopack SSR/1000 modules 2580.35ms ± 10.53ms 2966.18ms ± 17.34ms +14.95% +12.69%
bench_startup/Turbopack CSR/1000 modules 1608.74ms ± 3.87ms 1995.92ms ± 11.71ms +24.07% +22.02%
bench_startup/Turbopack RCC/1000 modules 2128.35ms ± 4.91ms 2361.75ms ± 5.75ms +10.97% +9.92%
bench_startup/Turbopack RSC/1000 modules 2045.09ms ± 4.42ms 2279.06ms ± 7.45ms +11.44% +10.24%
bench_startup/Turbopack SSR/1000 modules 1728.56ms ± 4.36ms 1958.77ms ± 1.90ms +13.32% +12.53%

@github-actions
Copy link
Contributor

Benchmark for a97c72c

Test Base PR % Significant %
bench_hmr_to_commit/Turbopack RCC/1000 modules 8589.62µs ± 57.45µs 9196.03µs ± 109.60µs +7.06% +3.13%
bench_hmr_to_commit/Turbopack RSC/1000 modules 450.92ms ± 2.20ms 465.24ms ± 3.45ms +3.17% +0.66%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8442.86µs ± 65.41µs 9085.71µs ± 56.97µs +7.61% +4.64%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7342.42µs ± 52.47µs 8139.65µs ± 102.32µs +10.86% +6.55%
bench_hmr_to_eval/Turbopack RCC/1000 modules 7568.48µs ± 51.72µs 8030.70µs ± 69.87µs +6.11% +2.86%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7501.00µs ± 45.80µs 8238.21µs ± 116.35µs +9.83% +5.44%
bench_hydration/Turbopack RCC/1000 modules 3353.06ms ± 9.10ms 3751.90ms ± 14.69ms +11.89% +10.42%
bench_hydration/Turbopack RSC/1000 modules 2785.68ms ± 5.75ms 3170.63ms ± 11.33ms +13.82% +12.54%
bench_hydration/Turbopack SSR/1000 modules 2629.69ms ± 6.52ms 2994.13ms ± 16.21ms +13.86% +12.07%
bench_startup/Turbopack CSR/1000 modules 1644.92ms ± 6.52ms 2090.12ms ± 15.77ms +27.07% +24.16%
bench_startup/Turbopack RCC/1000 modules 2162.12ms ± 4.99ms 2378.11ms ± 7.82ms +9.99% +8.76%
bench_startup/Turbopack RSC/1000 modules 2055.92ms ± 5.84ms 2286.75ms ± 6.00ms +11.23% +10.02%
bench_startup/Turbopack SSR/1000 modules 1732.29ms ± 2.96ms 1965.91ms ± 3.78ms +13.49% +12.66%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8214.56µs ± 82.70µs 8788.45µs ± 232.27µs +6.99%
bench_hmr_to_commit/Turbopack RCC/1000 modules 8589.62µs ± 57.45µs 9196.03µs ± 109.60µs +7.06% +3.13%
bench_hmr_to_commit/Turbopack RSC/1000 modules 450.92ms ± 2.20ms 465.24ms ± 3.45ms +3.17% +0.66%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8442.86µs ± 65.41µs 9085.71µs ± 56.97µs +7.61% +4.64%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7342.42µs ± 52.47µs 8139.65µs ± 102.32µs +10.86% +6.55%
bench_hmr_to_eval/Turbopack RCC/1000 modules 7568.48µs ± 51.72µs 8030.70µs ± 69.87µs +6.11% +2.86%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7501.00µs ± 45.80µs 8238.21µs ± 116.35µs +9.83% +5.44%
bench_hydration/Turbopack RCC/1000 modules 3353.06ms ± 9.10ms 3751.90ms ± 14.69ms +11.89% +10.42%
bench_hydration/Turbopack RSC/1000 modules 2785.68ms ± 5.75ms 3170.63ms ± 11.33ms +13.82% +12.54%
bench_hydration/Turbopack SSR/1000 modules 2629.69ms ± 6.52ms 2994.13ms ± 16.21ms +13.86% +12.07%
bench_startup/Turbopack CSR/1000 modules 1644.92ms ± 6.52ms 2090.12ms ± 15.77ms +27.07% +24.16%
bench_startup/Turbopack RCC/1000 modules 2162.12ms ± 4.99ms 2378.11ms ± 7.82ms +9.99% +8.76%
bench_startup/Turbopack RSC/1000 modules 2055.92ms ± 5.84ms 2286.75ms ± 6.00ms +11.23% +10.02%
bench_startup/Turbopack SSR/1000 modules 1732.29ms ± 2.96ms 1965.91ms ± 3.78ms +13.49% +12.66%

@github-actions
Copy link
Contributor

Benchmark for 60003ab

Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8095.66µs ± 36.01µs 8931.54µs ± 76.68µs +10.33% +7.47%
bench_hmr_to_commit/Turbopack RCC/1000 modules 8445.39µs ± 45.34µs 8938.76µs ± 80.50µs +5.84% +2.83%
bench_hmr_to_commit/Turbopack RSC/1000 modules 440.01ms ± 1.80ms 453.78ms ± 1.31ms +3.13% +1.70%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8245.52µs ± 69.61µs 8665.49µs ± 86.86µs +5.09% +1.28%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7117.85µs ± 47.71µs 7845.77µs ± 150.65µs +10.23% +4.59%
bench_hmr_to_eval/Turbopack RCC/1000 modules 7451.80µs ± 48.60µs 7770.14µs ± 72.98µs +4.27% +1.00%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7303.67µs ± 53.91µs 8015.11µs ± 100.93µs +9.74% +5.42%
bench_hydration/Turbopack RCC/1000 modules 3243.75ms ± 11.23ms 3707.14ms ± 19.58ms +14.29% +12.30%
bench_hydration/Turbopack RSC/1000 modules 2741.60ms ± 10.04ms 3115.93ms ± 15.23ms +13.65% +11.72%
bench_hydration/Turbopack SSR/1000 modules 2526.18ms ± 5.10ms 2925.52ms ± 14.97ms +15.81% +14.16%
bench_startup/Turbopack CSR/1000 modules 1597.01ms ± 4.89ms 1968.44ms ± 23.64ms +23.26% +19.56%
bench_startup/Turbopack RCC/1000 modules 2098.62ms ± 4.28ms 2311.19ms ± 7.13ms +10.13% +9.01%
bench_startup/Turbopack RSC/1000 modules 2020.67ms ± 7.08ms 2232.66ms ± 3.91ms +10.49% +9.34%
bench_startup/Turbopack SSR/1000 modules 1705.95ms ± 5.32ms 1911.75ms ± 5.67ms +12.06% +10.71%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8095.66µs ± 36.01µs 8931.54µs ± 76.68µs +10.33% +7.47%
bench_hmr_to_commit/Turbopack RCC/1000 modules 8445.39µs ± 45.34µs 8938.76µs ± 80.50µs +5.84% +2.83%
bench_hmr_to_commit/Turbopack RSC/1000 modules 440.01ms ± 1.80ms 453.78ms ± 1.31ms +3.13% +1.70%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8245.52µs ± 69.61µs 8665.49µs ± 86.86µs +5.09% +1.28%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7117.85µs ± 47.71µs 7845.77µs ± 150.65µs +10.23% +4.59%
bench_hmr_to_eval/Turbopack RCC/1000 modules 7451.80µs ± 48.60µs 7770.14µs ± 72.98µs +4.27% +1.00%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7303.67µs ± 53.91µs 8015.11µs ± 100.93µs +9.74% +5.42%
bench_hydration/Turbopack RCC/1000 modules 3243.75ms ± 11.23ms 3707.14ms ± 19.58ms +14.29% +12.30%
bench_hydration/Turbopack RSC/1000 modules 2741.60ms ± 10.04ms 3115.93ms ± 15.23ms +13.65% +11.72%
bench_hydration/Turbopack SSR/1000 modules 2526.18ms ± 5.10ms 2925.52ms ± 14.97ms +15.81% +14.16%
bench_startup/Turbopack CSR/1000 modules 1597.01ms ± 4.89ms 1968.44ms ± 23.64ms +23.26% +19.56%
bench_startup/Turbopack RCC/1000 modules 2098.62ms ± 4.28ms 2311.19ms ± 7.13ms +10.13% +9.01%
bench_startup/Turbopack RSC/1000 modules 2020.67ms ± 7.08ms 2232.66ms ± 3.91ms +10.49% +9.34%
bench_startup/Turbopack SSR/1000 modules 1705.95ms ± 5.32ms 1911.75ms ± 5.67ms +12.06% +10.71%

@jridgewell jridgewell requested review from sokra and removed request for tknickman and arlyon January 26, 2023 19:36
@@ -17,6 +17,7 @@ mime = "0.3.16"
once_cell = "1.13.0"
qstring = "0.7.2"
regex = "1.6.0"
reqwest = { workspace = true, features = ["stream"] }
Copy link
Member

Choose a reason for hiding this comment

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

Is this still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed in a follow up. This was part of the initial work where we would make an actual HTTP request to a router server spun up by Next.js during init.


const [_, response] = await Promise.all([
resolveRoute(serverRequest, serverResponse),
handleClientResponse(ipc, clientResponsePromise),
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it's cleaning to pass only the clientResponse to the method?

Suggested change
handleClientResponse(ipc, clientResponsePromise),
async () => handleClientResponse(ipc, await clientResponsePromise),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored.

_ipc: Ipc<RouterRequest, IpcOutgoingMessage>,
clientResponsePromise: Promise<IncomingMessage>
): Promise<MessageData | void> {
const clientResponse = await clientResponsePromise;
Copy link
Member

Choose a reason for hiding this comment

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

That looks a bit weird

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored.

@wbinnssmith wbinnssmith added the pr: automerge Kodiak will merge these automatically after checks pass label Jan 26, 2023
@sokra sokra merged commit 3bbbc47 into main Jan 26, 2023
@sokra sokra deleted the jrl-routes-callback branch January 26, 2023 20:15
jridgewell added a commit that referenced this pull request Jan 26, 2023
This completes a few review requests from #3446.
jridgewell added a commit that referenced this pull request Jan 26, 2023
This completes a few review requests from #3446.
Copy link
Contributor Author

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

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

Review requests addressed in #3501

@@ -17,6 +17,7 @@ mime = "0.3.16"
once_cell = "1.13.0"
qstring = "0.7.2"
regex = "1.6.0"
reqwest = { workspace = true, features = ["stream"] }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed in a follow up. This was part of the initial work where we would make an actual HTTP request to a router server spun up by Next.js during init.

_ipc: Ipc<RouterRequest, IpcOutgoingMessage>,
clientResponsePromise: Promise<IncomingMessage>
): Promise<MessageData | void> {
const clientResponse = await clientResponsePromise;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored.


const [_, response] = await Promise.all([
resolveRoute(serverRequest, serverResponse),
handleClientResponse(ipc, clientResponsePromise),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored.

@github-actions
Copy link
Contributor

Benchmark for 096307e

Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8463.05µs ± 50.88µs 9333.65µs ± 132.07µs +10.29% +5.89%
bench_hmr_to_commit/Turbopack RCC/1000 modules 8649.30µs ± 68.79µs 9413.50µs ± 135.50µs +8.84% +4.05%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8450.13µs ± 85.54µs 9135.07µs ± 81.13µs +8.11% +4.08%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7905.79µs ± 61.55µs 8598.16µs ± 49.91µs +8.76% +5.85%
bench_hmr_to_eval/Turbopack RCC/1000 modules 7957.60µs ± 59.32µs 8522.73µs ± 87.85µs +7.10% +3.35%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7947.23µs ± 84.92µs 8784.11µs ± 112.07µs +10.53% +5.46%
bench_hydration/Turbopack RCC/1000 modules 3222.27ms ± 10.03ms 3659.04ms ± 8.61ms +13.55% +12.32%
bench_hydration/Turbopack RSC/1000 modules 2825.51ms ± 10.70ms 3240.62ms ± 10.18ms +14.69% +13.11%
bench_hydration/Turbopack SSR/1000 modules 2684.12ms ± 9.50ms 3049.73ms ± 12.42ms +13.62% +11.90%
bench_startup/Turbopack CSR/1000 modules 1618.55ms ± 3.70ms 2026.26ms ± 14.14ms +25.19% +22.88%
bench_startup/Turbopack RCC/1000 modules 2212.22ms ± 9.59ms 2407.16ms ± 5.59ms +8.81% +7.38%
bench_startup/Turbopack RSC/1000 modules 2079.01ms ± 3.64ms 2284.33ms ± 7.02ms +9.88% +8.82%
bench_startup/Turbopack SSR/1000 modules 1758.52ms ± 4.30ms 1955.62ms ± 4.18ms +11.21% +10.19%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 8463.05µs ± 50.88µs 9333.65µs ± 132.07µs +10.29% +5.89%
bench_hmr_to_commit/Turbopack RCC/1000 modules 8649.30µs ± 68.79µs 9413.50µs ± 135.50µs +8.84% +4.05%
bench_hmr_to_commit/Turbopack RSC/1000 modules 450.63ms ± 2.06ms 452.98ms ± 3.64ms +0.52%
bench_hmr_to_commit/Turbopack SSR/1000 modules 8450.13µs ± 85.54µs 9135.07µs ± 81.13µs +8.11% +4.08%
bench_hmr_to_eval/Turbopack CSR/1000 modules 7905.79µs ± 61.55µs 8598.16µs ± 49.91µs +8.76% +5.85%
bench_hmr_to_eval/Turbopack RCC/1000 modules 7957.60µs ± 59.32µs 8522.73µs ± 87.85µs +7.10% +3.35%
bench_hmr_to_eval/Turbopack SSR/1000 modules 7947.23µs ± 84.92µs 8784.11µs ± 112.07µs +10.53% +5.46%
bench_hydration/Turbopack RCC/1000 modules 3222.27ms ± 10.03ms 3659.04ms ± 8.61ms +13.55% +12.32%
bench_hydration/Turbopack RSC/1000 modules 2825.51ms ± 10.70ms 3240.62ms ± 10.18ms +14.69% +13.11%
bench_hydration/Turbopack SSR/1000 modules 2684.12ms ± 9.50ms 3049.73ms ± 12.42ms +13.62% +11.90%
bench_startup/Turbopack CSR/1000 modules 1618.55ms ± 3.70ms 2026.26ms ± 14.14ms +25.19% +22.88%
bench_startup/Turbopack RCC/1000 modules 2212.22ms ± 9.59ms 2407.16ms ± 5.59ms +8.81% +7.38%
bench_startup/Turbopack RSC/1000 modules 2079.01ms ± 3.64ms 2284.33ms ± 7.02ms +9.88% +8.82%
bench_startup/Turbopack SSR/1000 modules 1758.52ms ± 4.30ms 1955.62ms ± 4.18ms +11.21% +10.19%

ijjk pushed a commit to vercel/next.js that referenced this pull request Jan 26, 2023
**Note**: This requires #45314,
otherwise the following error is shown, but does not block builds:

```
error - [build] examples/create-app
  Error evaluating Node.js code
  TypeError: makeResolver is not a function
    at getResolveRoute (path/to/next.js/examples/create-app/.next/build/chunks/router.js:21:18)
    at async Module.route (path/to/next.js/examples/create-app/.next/build/chunks/router.js:24:36)
    at async Module.run (path/to/next.js/examples/create-app/.next/build/chunks/[turbopack-node]_ipc_evaluate.ts.js:19:39)
```

### Features

- vercel/turborepo#3446
- vercel/turborepo#3396
- vercel/turborepo#3499

### Bug fixes

- vercel/turborepo#3433

### Misc

- vercel/turborepo#3479
jridgewell added a commit that referenced this pull request Jan 27, 2023
This completes a few review requests from #3446.
ijjk added a commit to vercel/next.js that referenced this pull request Jan 27, 2023
jridgewell added a commit to vercel/next.js that referenced this pull request Mar 10, 2023
This implements routing by using a-yet-to-be-implemented API exposed by
Next.js. The API follows something similar to:

```typescript
type MakeResolver = (config: NextConfig) => Resolver;
type Resolver = (IncomingMessage, ServerResponse) => Promise<void> | void;

import { makeResolver } from "next/dist/...";
const resolver  = makeResolver(nextConfig as object);

// Later, once we have a request we'd like to route:
// We don't care what the promise resolved to, we just want it to settle.
await resolver(req, res);
```

The resolver can do 1 of 3 things with this:
1. ~~Return a redirect response~~ Removed
2. Return a rewrite response
3. Stream a middleware response

> ~~1. Return a redirect response~~

<details>

First, ensure a `x-nextjs-route-result: 1` header is present on the
response. Then return a JSON encoded body:

```typescript
{
  url: string,
  statusCode: u16,
  headers: Record<string, string>
  isRedirect: true
}
```

The Rust server will then respond with a redirect using to the
appropriate location.

</details>

> 2. Return a rewrite response

First, ensure a `x-nextjs-route-result: 1` header is present on the
response. Then return a JSON encoded body:

```typescript
{
  url: string,
  headers: Record<string, string>
}
```

The Rust server will use this updated URL to request content from our
handlers.

> 3. Stream a middleware response

Ensure `x-nextjs-route-result` header **is not present** on the
response. All headers will be sent back, and the body will be streamed
back to the browser.

- - -

TODO:
- ~~Do `headers` actually matter to a `redirect`~~ Yes?
- ~~Does `statusCode` actually matter to a `rewrite`?~~ No
- ~~We can't handle streaming body responses yet.~~ Mocked by buffering.

Fixes WEB-228

Co-authored-by: JJ Kasper <jj@jjsweb.site>
jridgewell added a commit to vercel/next.js that referenced this pull request Mar 10, 2023
sokra pushed a commit to vercel/next.js that referenced this pull request Mar 13, 2023
This implements routing by using a-yet-to-be-implemented API exposed by
Next.js. The API follows something similar to:

```typescript
type MakeResolver = (config: NextConfig) => Resolver;
type Resolver = (IncomingMessage, ServerResponse) => Promise<void> | void;

import { makeResolver } from "next/dist/...";
const resolver  = makeResolver(nextConfig as object);

// Later, once we have a request we'd like to route:
// We don't care what the promise resolved to, we just want it to settle.
await resolver(req, res);
```

The resolver can do 1 of 3 things with this:
1. ~~Return a redirect response~~ Removed
2. Return a rewrite response
3. Stream a middleware response

> ~~1. Return a redirect response~~

<details>

First, ensure a `x-nextjs-route-result: 1` header is present on the
response. Then return a JSON encoded body:

```typescript
{
  url: string,
  statusCode: u16,
  headers: Record<string, string>
  isRedirect: true
}
```

The Rust server will then respond with a redirect using to the
appropriate location.

</details>

> 2. Return a rewrite response

First, ensure a `x-nextjs-route-result: 1` header is present on the
response. Then return a JSON encoded body:

```typescript
{
  url: string,
  headers: Record<string, string>
}
```

The Rust server will use this updated URL to request content from our
handlers.

> 3. Stream a middleware response

Ensure `x-nextjs-route-result` header **is not present** on the
response. All headers will be sent back, and the body will be streamed
back to the browser.

- - -

TODO:
- ~~Do `headers` actually matter to a `redirect`~~ Yes?
- ~~Does `statusCode` actually matter to a `rewrite`?~~ No
- ~~We can't handle streaming body responses yet.~~ Mocked by buffering.

Fixes WEB-228

Co-authored-by: JJ Kasper <jj@jjsweb.site>
sokra pushed a commit to vercel/next.js that referenced this pull request Mar 13, 2023
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 25, 2024
This implements routing by using a-yet-to-be-implemented API exposed by
Next.js. The API follows something similar to:

```typescript
type MakeResolver = (config: NextConfig) => Resolver;
type Resolver = (IncomingMessage, ServerResponse) => Promise<void> | void;

import { makeResolver } from "next/dist/...";
const resolver  = makeResolver(nextConfig as object);

// Later, once we have a request we'd like to route:
// We don't care what the promise resolved to, we just want it to settle.
await resolver(req, res);
```

The resolver can do 1 of 3 things with this:
1. ~~Return a redirect response~~ Removed
2. Return a rewrite response
3. Stream a middleware response

> ~~1. Return a redirect response~~

<details>

First, ensure a `x-nextjs-route-result: 1` header is present on the
response. Then return a JSON encoded body:

```typescript
{
  url: string,
  statusCode: u16,
  headers: Record<string, string>
  isRedirect: true
}
```

The Rust server will then respond with a redirect using to the
appropriate location.

</details>

> 2. Return a rewrite response

First, ensure a `x-nextjs-route-result: 1` header is present on the
response. Then return a JSON encoded body:

```typescript
{
  url: string,
  headers: Record<string, string>
}
```

The Rust server will use this updated URL to request content from our
handlers.

> 3. Stream a middleware response

Ensure `x-nextjs-route-result` header **is not present** on the
response. All headers will be sent back, and the body will be streamed
back to the browser.

- - -

TODO:
- ~~Do `headers` actually matter to a `redirect`~~ Yes?
- ~~Does `statusCode` actually matter to a `rewrite`?~~ No
- ~~We can't handle streaming body responses yet.~~ Mocked by buffering.

Fixes WEB-228

Co-authored-by: JJ Kasper <jj@jjsweb.site>
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 29, 2024
This implements routing by using a-yet-to-be-implemented API exposed by
Next.js. The API follows something similar to:

```typescript
type MakeResolver = (config: NextConfig) => Resolver;
type Resolver = (IncomingMessage, ServerResponse) => Promise<void> | void;

import { makeResolver } from "next/dist/...";
const resolver  = makeResolver(nextConfig as object);

// Later, once we have a request we'd like to route:
// We don't care what the promise resolved to, we just want it to settle.
await resolver(req, res);
```

The resolver can do 1 of 3 things with this:
1. ~~Return a redirect response~~ Removed
2. Return a rewrite response
3. Stream a middleware response

> ~~1. Return a redirect response~~

<details>

First, ensure a `x-nextjs-route-result: 1` header is present on the
response. Then return a JSON encoded body:

```typescript
{
  url: string,
  statusCode: u16,
  headers: Record<string, string>
  isRedirect: true
}
```

The Rust server will then respond with a redirect using to the
appropriate location.

</details>

> 2. Return a rewrite response

First, ensure a `x-nextjs-route-result: 1` header is present on the
response. Then return a JSON encoded body:

```typescript
{
  url: string,
  headers: Record<string, string>
}
```

The Rust server will use this updated URL to request content from our
handlers.

> 3. Stream a middleware response

Ensure `x-nextjs-route-result` header **is not present** on the
response. All headers will be sent back, and the body will be streamed
back to the browser.

- - -

TODO:
- ~~Do `headers` actually matter to a `redirect`~~ Yes?
- ~~Does `statusCode` actually matter to a `rewrite`?~~ No
- ~~We can't handle streaming body responses yet.~~ Mocked by buffering.

Fixes WEB-228

Co-authored-by: JJ Kasper <jj@jjsweb.site>
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Aug 1, 2024
This implements routing by using a-yet-to-be-implemented API exposed by
Next.js. The API follows something similar to:

```typescript
type MakeResolver = (config: NextConfig) => Resolver;
type Resolver = (IncomingMessage, ServerResponse) => Promise<void> | void;

import { makeResolver } from "next/dist/...";
const resolver  = makeResolver(nextConfig as object);

// Later, once we have a request we'd like to route:
// We don't care what the promise resolved to, we just want it to settle.
await resolver(req, res);
```

The resolver can do 1 of 3 things with this:
1. ~~Return a redirect response~~ Removed
2. Return a rewrite response
3. Stream a middleware response

> ~~1. Return a redirect response~~

<details>

First, ensure a `x-nextjs-route-result: 1` header is present on the
response. Then return a JSON encoded body:

```typescript
{
  url: string,
  statusCode: u16,
  headers: Record<string, string>
  isRedirect: true
}
```

The Rust server will then respond with a redirect using to the
appropriate location.

</details>

> 2. Return a rewrite response

First, ensure a `x-nextjs-route-result: 1` header is present on the
response. Then return a JSON encoded body:

```typescript
{
  url: string,
  headers: Record<string, string>
}
```

The Rust server will use this updated URL to request content from our
handlers.

> 3. Stream a middleware response

Ensure `x-nextjs-route-result` header **is not present** on the
response. All headers will be sent back, and the body will be streamed
back to the browser.

- - -

TODO:
- ~~Do `headers` actually matter to a `redirect`~~ Yes?
- ~~Does `statusCode` actually matter to a `rewrite`?~~ No
- ~~We can't handle streaming body responses yet.~~ Mocked by buffering.

Fixes WEB-228

Co-authored-by: JJ Kasper <jj@jjsweb.site>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: automerge Kodiak will merge these automatically after checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants