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

[Turbopack] name the module factory function in dev mode #73553

Draft
wants to merge 4 commits into
base: canary
Choose a base branch
from

Conversation

sokra
Copy link
Member

@sokra sokra commented Dec 5, 2024

What?

In development give the module factory a useful name, so it's clear in stack traces that this is the module evaluation part of the execution.

This also fixes some bugs with the stack trace parser, which seems to struggle if function names contain brackets. The automatically inferred function name would be the module id, which contains brackets.

Copy link
Member Author

sokra commented Dec 5, 2024

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ijjk
Copy link
Member

ijjk commented Dec 5, 2024

Failing test suites

Commit: f1bb2ed

pnpm test-dev test/development/middleware-errors/index.test.ts

  • middleware - development errors > when throwing while loading the module > logs the error correctly
Expand output

● middleware - development errors › when throwing while loading the module › logs the error correctly

expect(received).toContain(expected) // indexOf

Expected substring: "
 ⨯ Error: booooom!

  at Object.__TURBOPACK__module__evaluation__ (../middleware.js:3:12)"
  Received string:    "   No config file found
     No config file found
     ▲ Next.js 15.1.1-canary.14 (Turbopack)
     - Local:        http://localhost:34815
     - Network:      http://95.217.250.160:34815·
   ✓ Starting...
     No config file found
  Creating turbopack project {
    dir: '/tmp/next-install-6079620fcd738cea7761f552beb1a79dd8c5b929bf7e4e6ecedc1f0a9f24a774',
    testMode: true
  }
   ✓ Compiled in 131ms
     No config file found
   ✓ Ready in 590ms
     No config file found
   ⨯ Error: booooom!
  at Module.__TURBOPACK__module__evaluation__ (../middleware.js:3:12)
    1 |
    2 |       import { NextResponse } from 'next/server'
  > 3 |       throw new Error('booooom!')
      |            ^
    4 |       export default function () {
    5 |         return NextResponse.next()
    6 |       }
   ○ Compiling /_error ...
   ✓ Compiled /_error in 626ms
  "
  at Object.toContain (development/middleware-errors/index.test.ts:210:41)

Read more about building and testing Next.js in contributing.md.

pnpm test-dev-turbo test/e2e/app-dir/use-cache-close-over-function/use-cache-close-over-function.test.ts (turbopack)

  • use-cache-close-over-function > should show the error overlay for server-side usage
Expand output

● use-cache-close-over-function › should show the error overlay for server-side usage

expect(received).toContain(expected) // indexOf

Expected substring: "Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with \"use server\". Or maybe you meant to call this function rather than return it.
  [function fn]
   ^^^^^^^^^^^

  at createCachedFn (../app/server/page.tsx:6:2)
      at [project]"
  Received string:    " ✓ Compiled /server in 232ms
  Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with \"use server\". Or maybe you meant to call this function rather than return it.
    [function fn]
     ^^^^^^^^^^^
  at createCachedFn (../app/server/page.tsx:6:2)
  at Module.__TURBOPACK__module__evaluation__ (../app/server/page.tsx:12:23)
  at [project]/.next-internal/server/app/server/page/actions.js { ACTIONS_MODULE0 => \"[project]/app/server/page.tsx [app-rsc] (ecmascript)\" } [app-rsc] (ecmascript) <module evaluation> (../.next/server/chunks/ssr/[root of the server]__402fca._.js:79:126)
  at [project]/.next-internal/server/app/server/page/actions.js { ACTIONS_MODULE0 => \"[project]/app/server/page.tsx [app-rsc] (ecmascript)\" } [app-rsc] (ecmascript) (../.next/server/chunks/ssr/[root of the server]__402fca._.js:101:324)
  at Object.<anonymous> (../.next/server/app/server/page.js:11:9)
    4 |   }
    5 |
  > 6 |   return async () => {
      |  ^
    7 |     'use cache'
    8 |     return Math.random() + fn()
    9 |   }
  Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with \"use server\". Or maybe you meant to call this function rather than return it.
    [function fn]
     ^^^^^^^^^^^
  at createCachedFn (../app/server/page.tsx:6:2)
  at Module.__TURBOPACK__module__evaluation__ (../app/server/page.tsx:12:23)
  at [project]/.next-internal/server/app/server/page/actions.js { ACTIONS_MODULE0 => \"[project]/app/server/page.tsx [app-rsc] (ecmascript)\" } [app-rsc] (ecmascript) <module evaluation> (../.next/server/chunks/ssr/[root of the server]__402fca._.js:79:126)
  at [project]/.next-internal/server/app/server/page/actions.js { ACTIONS_MODULE0 => \"[project]/app/server/page.tsx [app-rsc] (ecmascript)\" } [app-rsc] (ecmascript) (../.next/server/chunks/ssr/[root of the server]__402fca._.js:101:324)
  at Object.<anonymous> (../.next/server/app/server/page.js:11:9)
    4 |   }
    5 |
  > 6 |   return async () => {
      |  ^
    7 |     'use cache'
    8 |     return Math.random() + fn()
    9 |   }
   ⨯ unhandledRejection: Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with \"use server\". Or maybe you meant to call this function rather than return it.
    [function fn]
     ^^^^^^^^^^^
  at createCachedFn (../app/server/page.tsx:6:2)
  at Module.__TURBOPACK__module__evaluation__ (../app/server/page.tsx:12:23)
  at [project]/.next-internal/server/app/server/page/actions.js { ACTIONS_MODULE0 => \"[project]/app/server/page.tsx [app-rsc] (ecmascript)\" } [app-rsc] (ecmascript) <module evaluation> (../.next/server/chunks/ssr/[root of the server]__402fca._.js:79:126)
  at [project]/.next-internal/server/app/server/page/actions.js { ACTIONS_MODULE0 => \"[project]/app/server/page.tsx [app-rsc] (ecmascript)\" } [app-rsc] (ecmascript) (../.next/server/chunks/ssr/[root of the server]__402fca._.js:101:324)
  at Object.<anonymous> (../.next/server/app/server/page.js:11:9)
    4 |   }
    5 |
  > 6 |   return async () => {
      |  ^
    7 |     'use cache'
    8 |     return Math.random() + fn()
    9 |   }
   ⨯ unhandledRejection:  Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with \"use server\". Or maybe you meant to call this function rather than return it.
    [function fn]
     ^^^^^^^^^^^
  at createCachedFn (../app/server/page.tsx:6:2)
  at Module.__TURBOPACK__module__evaluation__ (../app/server/page.tsx:12:23)
  at [project]/.next-internal/server/app/server/page/actions.js { ACTIONS_MODULE0 => \"[project]/app/server/page.tsx [app-rsc] (ecmascript)\" } [app-rsc] (ecmascript) <module evaluation> (../.next/server/chunks/ssr/[root of the server]__402fca._.js:79:126)
  at [project]/.next-internal/server/app/server/page/actions.js { ACTIONS_MODULE0 => \"[project]/app/server/page.tsx [app-rsc] (ecmascript)\" } [app-rsc] (ecmascript) (../.next/server/chunks/ssr/[root of the server]__402fca._.js:101:324)
  at Object.<anonymous> (../.next/server/app/server/page.js:11:9)
    4 |   }
    5 |
  > 6 |   return async () => {
      |  ^
    7 |     'use cache'
    8 |     return Math.random() + fn()
    9 |   }
   ⨯ Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with \"use server\". Or maybe you meant to call this function rather than return it.
    [function fn]
     ^^^^^^^^^^^
  at createCachedFn (../app/server/page.tsx:6:2)
  at Module.__TURBOPACK__module__evaluation__ (../app/server/page.tsx:12:23)
  at [project]/.next-internal/server/app/server/page/actions.js { ACTIONS_MODULE0 => \"[project]/app/server/page.tsx [app-rsc] (ecmascript)\" } [app-rsc] (ecmascript) <module evaluation> (../.next/server/chunks/ssr/[root of the server]__402fca._.js:79:126)
  at [project]/.next-internal/server/app/server/page/actions.js { ACTIONS_MODULE0 => \"[project]/app/server/page.tsx [app-rsc] (ecmascript)\" } [app-rsc] (ecmascript) (../.next/server/chunks/ssr/[root of the server]__402fca._.js:101:324)
  at Object.<anonymous> (../.next/server/app/server/page.js:11:9)
    4 |   }
    5 |
  > 6 |   return async () => {
      |  ^
    7 |     'use cache'
    8 |     return Math.random() + fn()
    9 |   } {
    digest: '1090586958'
  }
   GET /server 200 in 780ms
  "
  at Object.toContain (e2e/app-dir/use-cache-close-over-function/use-cache-close-over-function.test.ts:108:25)

Read more about building and testing Next.js in contributing.md.

pnpm test-dev-turbo test/development/acceptance/ReactRefreshLogBox.test.ts (turbopack)

  • ReactRefreshLogBox turbo > module init error not shown
Expand output

● ReactRefreshLogBox turbo › module init error not shown

expect(received).toMatchSnapshot()

Snapshot name: `ReactRefreshLogBox turbo module init error not shown 1`

- Snapshot  - 1
+ Received  + 1

@@ -1,6 +1,6 @@
- index.js (3:7) @ Object.{module evaluation}
+ index.js (3:7) @ Module.{module evaluation}

    1 | // top offset for snapshot
    2 | import * as React from 'react';
  > 3 | throw new Error('no')
      |       ^

  86 |
  87 |     await session.assertHasRedbox()
> 88 |     expect(await session.getRedboxSource()).toMatchSnapshot()
     |                                             ^
  89 |   })
  90 |
  91 |   // https://github.com/pmmmwh/react-refresh-webpack-plugin/pull/3#issuecomment-554152127

  at Object.toMatchSnapshot (development/acceptance/ReactRefreshLogBox.test.ts:88:45)

Read more about building and testing Next.js in contributing.md.

pnpm test-dev-turbo test/development/acceptance-app/ReactRefreshLogBox.test.ts (turbopack)

  • ReactRefreshLogBox app turbo > should collapse bundler internal stack frames
Expand output

● ReactRefreshLogBox app turbo › should collapse bundler internal stack frames

expect(received).toMatchInlineSnapshot(snapshot)

Snapshot name: `ReactRefreshLogBox app turbo should collapse bundler internal stack frames 1`

- Snapshot  - 1
+ Received  + 1

- app/utils.ts (1:7) @ Object.{module evaluation}
+ app/utils.ts (1:7) @ Module.{module evaluation}

  > 1 | throw new Error('utils error')
      |       ^
    2 | export function foo(){}
    3 |

  1191 |
  1192 |     if (isTurbopack) {
> 1193 |       expect(source).toMatchInlineSnapshot(`
       |                      ^
  1194 |         "app/utils.ts (1:7) @ Object.{module evaluation}
  1195 |
  1196 |         > 1 | throw new Error('utils error')

  at Object.toMatchInlineSnapshot (development/acceptance-app/ReactRefreshLogBox.test.ts:1193:22)

● ReactRefreshLogBox app turbo › should collapse bundler internal stack frames

expect(received).toMatchInlineSnapshot(snapshot)

Snapshot name: `ReactRefreshLogBox app turbo should collapse bundler internal stack frames 2`

Snapshot: "at Object.{module evaluation} (app/page.js (2:1))"
Received: "at Module.{module evaluation} (app/page.js (2:1))"

  1212 |     if (isTurbopack) {
  1213 |       // FIXME: display the sourcemapped stack frames
> 1214 |       expect(stackFrames).toMatchInlineSnapshot(
       |                           ^
  1215 |         `"at Object.{module evaluation} (app/page.js (2:1))"`
  1216 |       )
  1217 |     } else {

  at Object.toMatchInlineSnapshot (development/acceptance-app/ReactRefreshLogBox.test.ts:1214:27)

Read more about building and testing Next.js in contributing.md.

@sokra sokra force-pushed the sokra/import-meta-url-monorepo branch from bae00fc to 1a55a49 Compare December 5, 2024 15:46
@sokra sokra force-pushed the sokra/module-factory-function-name branch from fd166b3 to 5c2d820 Compare December 5, 2024 15:46
@ijjk
Copy link
Member

ijjk commented Dec 5, 2024

Stats from current PR

Default Build (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary vercel/next.js sokra/module-factory-function-name Change
buildDuration 26.8s 23.8s N/A
buildDurationCached 23.9s 20.6s N/A
nodeModulesSize 416 MB 416 MB
nextStartRea..uration (ms) 700ms 842ms ⚠️ +142ms
Client Bundles (main, webpack)
vercel/next.js canary vercel/next.js sokra/module-factory-function-name Change
1187-HASH.js gzip 52.4 kB 52.4 kB N/A
8276.HASH.js gzip 169 B 168 B N/A
8377-HASH.js gzip 5.36 kB 5.36 kB N/A
bccd1874-HASH.js gzip 52.8 kB 52.8 kB N/A
framework-HASH.js gzip 57.5 kB 57.5 kB N/A
main-app-HASH.js gzip 232 B 235 B N/A
main-HASH.js gzip 34.1 kB 34.1 kB N/A
webpack-HASH.js gzip 1.71 kB 1.71 kB N/A
Overall change 0 B 0 B
Legacy Client Bundles (polyfills)
vercel/next.js canary vercel/next.js sokra/module-factory-function-name Change
polyfills-HASH.js gzip 39.4 kB 39.4 kB
Overall change 39.4 kB 39.4 kB
Client Pages
vercel/next.js canary vercel/next.js sokra/module-factory-function-name Change
_app-HASH.js gzip 193 B 193 B
_error-HASH.js gzip 193 B 193 B
amp-HASH.js gzip 512 B 510 B N/A
css-HASH.js gzip 343 B 342 B N/A
dynamic-HASH.js gzip 1.84 kB 1.84 kB
edge-ssr-HASH.js gzip 265 B 265 B
head-HASH.js gzip 363 B 362 B N/A
hooks-HASH.js gzip 393 B 392 B N/A
image-HASH.js gzip 4.49 kB 4.49 kB N/A
index-HASH.js gzip 268 B 268 B
link-HASH.js gzip 2.35 kB 2.34 kB N/A
routerDirect..HASH.js gzip 328 B 328 B
script-HASH.js gzip 397 B 397 B
withRouter-HASH.js gzip 323 B 326 B N/A
1afbb74e6ecf..834.css gzip 106 B 106 B
Overall change 3.59 kB 3.59 kB
Client Build Manifests
vercel/next.js canary vercel/next.js sokra/module-factory-function-name Change
_buildManifest.js gzip 749 B 746 B N/A
Overall change 0 B 0 B
Rendered Page Sizes
vercel/next.js canary vercel/next.js sokra/module-factory-function-name Change
index.html gzip 524 B 524 B
link.html gzip 538 B 538 B
withRouter.html gzip 520 B 521 B N/A
Overall change 1.06 kB 1.06 kB
Edge SSR bundle Size
vercel/next.js canary vercel/next.js sokra/module-factory-function-name Change
edge-ssr.js gzip 129 kB 129 kB N/A
page.js gzip 206 kB 206 kB N/A
Overall change 0 B 0 B
Middleware size
vercel/next.js canary vercel/next.js sokra/module-factory-function-name Change
middleware-b..fest.js gzip 669 B 665 B N/A
middleware-r..fest.js gzip 155 B 156 B N/A
middleware.js gzip 31.3 kB 31.3 kB N/A
edge-runtime..pack.js gzip 844 B 844 B
Overall change 844 B 844 B
Next Runtimes
vercel/next.js canary vercel/next.js sokra/module-factory-function-name Change
274-experime...dev.js gzip 322 B 322 B
274.runtime.dev.js gzip 314 B 314 B
app-page-exp...dev.js gzip 359 kB 359 kB
app-page-exp..prod.js gzip 129 kB 129 kB
app-page-tur..prod.js gzip 142 kB 142 kB
app-page-tur..prod.js gzip 137 kB 137 kB
app-page.run...dev.js gzip 348 kB 348 kB
app-page.run..prod.js gzip 125 kB 125 kB
app-route-ex...dev.js gzip 37.5 kB 37.5 kB
app-route-ex..prod.js gzip 25.5 kB 25.5 kB
app-route-tu..prod.js gzip 25.5 kB 25.5 kB
app-route-tu..prod.js gzip 25.4 kB 25.4 kB
app-route.ru...dev.js gzip 39.2 kB 39.2 kB
app-route.ru..prod.js gzip 25.4 kB 25.4 kB
pages-api-tu..prod.js gzip 9.69 kB 9.69 kB
pages-api.ru...dev.js gzip 11.6 kB 11.6 kB
pages-api.ru..prod.js gzip 9.68 kB 9.68 kB
pages-turbo...prod.js gzip 21.7 kB 21.7 kB
pages.runtim...dev.js gzip 27.5 kB 27.5 kB
pages.runtim..prod.js gzip 21.7 kB 21.7 kB
server.runti..prod.js gzip 916 kB 916 kB
Overall change 2.44 MB 2.44 MB
build cache Overall increase ⚠️
vercel/next.js canary vercel/next.js sokra/module-factory-function-name Change
0.pack gzip 2.08 MB 2.08 MB ⚠️ +3.55 kB
index.pack gzip 74.4 kB 74.6 kB ⚠️ +220 B
Overall change 2.15 MB 2.16 MB ⚠️ +3.77 kB
Diff details
Diff for main-HASH.js

Diff too large to display

Commit: f1bb2ed

@sokra sokra force-pushed the sokra/import-meta-url-monorepo branch from 1a55a49 to 621016a Compare December 5, 2024 16:10
@sokra sokra force-pushed the sokra/module-factory-function-name branch from 5c2d820 to 58c3140 Compare December 5, 2024 16:10
@sokra sokra changed the title name the module factory function in dev mode [Turbopack] name the module factory function in dev mode Dec 5, 2024
@sokra sokra added the CI Bypass Graphite Optimization Ignore Graphite CI optimizations, run the full CI suite. https://graphite.dev/docs/stacking-and-ci label Dec 6, 2024 — with Graphite App
@sokra sokra force-pushed the sokra/import-meta-url-monorepo branch from 621016a to ffef7cb Compare December 6, 2024 08:18
@sokra sokra force-pushed the sokra/module-factory-function-name branch from 58c3140 to cd18f19 Compare December 6, 2024 08:18
@sokra sokra force-pushed the sokra/import-meta-url-monorepo branch from ffef7cb to 3d93491 Compare December 6, 2024 08:54
@sokra sokra force-pushed the sokra/module-factory-function-name branch from cd18f19 to 8238121 Compare December 6, 2024 08:54
@sokra sokra force-pushed the sokra/import-meta-url-monorepo branch from 3d93491 to 8d96637 Compare December 9, 2024 07:34
@sokra sokra force-pushed the sokra/module-factory-function-name branch from 8238121 to 011e151 Compare December 9, 2024 07:34
@sokra sokra force-pushed the sokra/import-meta-url-monorepo branch from 8d96637 to 2a29b4d Compare December 19, 2024 08:28
@sokra sokra force-pushed the sokra/module-factory-function-name branch from 011e151 to 304ebeb Compare December 19, 2024 08:28
@sokra sokra force-pushed the sokra/import-meta-url-monorepo branch from 2a29b4d to 3ac7f43 Compare December 19, 2024 10:25
@sokra sokra force-pushed the sokra/module-factory-function-name branch from 304ebeb to ba1434f Compare December 19, 2024 10:25
@sokra sokra force-pushed the sokra/import-meta-url-monorepo branch 2 times, most recently from 0eeeafe to becc48a Compare December 19, 2024 11:58
@sokra sokra force-pushed the sokra/module-factory-function-name branch from ba1434f to 099b794 Compare December 19, 2024 11:58
@sokra sokra force-pushed the sokra/import-meta-url-monorepo branch from becc48a to caff3ee Compare December 20, 2024 12:33
@sokra sokra force-pushed the sokra/module-factory-function-name branch from 099b794 to 806b3b9 Compare December 20, 2024 12:33
@sokra sokra changed the base branch from sokra/import-meta-url-monorepo to graphite-base/73553 December 20, 2024 15:34
@sokra sokra force-pushed the sokra/module-factory-function-name branch from 806b3b9 to f4cf432 Compare December 20, 2024 15:35
@sokra sokra changed the base branch from graphite-base/73553 to canary December 20, 2024 15:36
@sokra sokra force-pushed the sokra/module-factory-function-name branch from f4cf432 to f1bb2ed Compare December 20, 2024 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Bypass Graphite Optimization Ignore Graphite CI optimizations, run the full CI suite. https://graphite.dev/docs/stacking-and-ci created-by: Turbopack team PRs by the Turbopack team. tests Turbopack Related to Turbopack with Next.js.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants