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(server): isolate component modules #29565

Closed
wants to merge 6 commits into from

Conversation

ctjlewis
Copy link
Contributor

@ctjlewis ctjlewis commented Oct 2, 2021

WIP to resolve issues encountered when adding global shims to an application. Because Next apps currently share context with the Next server itself, it is possible (and trivial) to write application code that breaks the server and prevents a perfectly valid component from rendering, i.e., you can run it with node .next/server/pages/_app.js and see the component render without issue, but the Next server itself will throw as a result of conflicts with application code.

This feature aims to isolate component module contexts using the Node.js vm module and prevent this possibility (and also better containerize Next applications). In general, it is safe to say we do not want application code to ever touch the Next server context, as they truly are separate processes. It is probably worth considering a review of other places where application code is naively require'd and replacing those calls with isolateRequire(...), but it seems like next/server/require.ts : requirePage() is the main concern.

See: Agoric/dapp-card-store#37

Bug

  • Related issues linked using fixes #number
  • Integration tests added
  • Errors have helpful link attached, see contributing.md

Feature

  • Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
  • Related issues linked using fixes #number
  • Integration tests added
  • Documentation added
  • Telemetry added. In case of a feature if it's used or not.
  • Errors have helpful link attached, see contributing.md

Documentation / Examples

  • Make sure the linting passes

@ijjk ijjk added the type: next label Oct 2, 2021
@ijjk

This comment has been minimized.

@ijjk

This comment has been minimized.

@ctjlewis
Copy link
Contributor Author

ctjlewis commented Oct 2, 2021

Some tricky conflicts going on. I just got a comment from @sokra in another thread, but many of the failing test errors seem to be Webpack-related, would appreciate a first-glance review for sure.

@ijjk
Copy link
Member

ijjk commented Jan 14, 2022

Failing test suites

Commit: e2ff1d0

test/development/acceptance/ReactRefreshLogBox.test.ts

  • ReactRefreshLogBox > module init error not shown
Expand output

● ReactRefreshLogBox › module init error not shown

expect(received).toMatchSnapshot()

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

- Snapshot  - 2
+ Received  + 2

- index.js (4:14) @ eval
+ index.js (4:8) @ <unknown>

    2 | // top offset for snapshot
    3 | import * as React from 'react';
  > 4 | throw new Error('no')
-     |      ^
+     |        ^
    5 | class ClassDefault extends React.Component {
    6 |   render() {
    7 |     return <h1>Default Export</h1>;

  242 |             return <h1>Default Export</h1>;
  243 |           }
> 244 |         }
      |          ^
  245 |
  246 |         export default ClassDefault;
  247 |       `

  at Object.<anonymous> (development/acceptance/ReactRefreshLogBox.test.ts:244:53)

@ijjk

This comment has been minimized.

This source for the module in this error overlay test changes from
`(eval)` to `(unknown)` when injected by Jest, and is purely cosmetic.
@ijjk
Copy link
Member

ijjk commented Jan 14, 2022

Stats from current PR

Default Build (Decrease detected ✓)
General Overall increase ⚠️
vercel/next.js canary ctjlewis/next.js isolate-component-requires Change
buildDuration 13.9s 14.1s ⚠️ +157ms
buildDurationCached 3.1s 3.2s ⚠️ +31ms
nodeModulesSize 354 MB 354 MB ⚠️ +1.18 kB
Page Load Tests Overall decrease ⚠️
vercel/next.js canary ctjlewis/next.js isolate-component-requires Change
/ failed reqs 0 0
/ total time (seconds) 2.872 7.934 ⚠️ +5.06
/ avg req/sec 870.34 315.12 ⚠️ -555.22
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.325 8.527 ⚠️ +7.2
/error-in-render avg req/sec 1886.33 293.2 ⚠️ -1593.13
Client Bundles (main, webpack, commons)
vercel/next.js canary ctjlewis/next.js isolate-component-requires Change
450.HASH.js gzip 179 B 179 B
framework-HASH.js gzip 42.2 kB 42.2 kB
main-HASH.js gzip 27.2 kB 27.2 kB
webpack-HASH.js gzip 1.44 kB 1.44 kB
Overall change 71 kB 71 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary ctjlewis/next.js isolate-component-requires Change
polyfills-HASH.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary ctjlewis/next.js isolate-component-requires Change
_app-HASH.js gzip 1.37 kB 1.37 kB
_error-HASH.js gzip 194 B 194 B
amp-HASH.js gzip 312 B 312 B
css-HASH.js gzip 326 B 326 B
dynamic-HASH.js gzip 2.37 kB 2.37 kB
head-HASH.js gzip 350 B 350 B
hooks-HASH.js gzip 919 B 919 B
image-HASH.js gzip 4.7 kB 4.7 kB
index-HASH.js gzip 263 B 263 B
link-HASH.js gzip 2.13 kB 2.13 kB
routerDirect..HASH.js gzip 321 B 321 B
script-HASH.js gzip 383 B 383 B
withRouter-HASH.js gzip 318 B 318 B
85e02e95b279..7e3.css gzip 107 B 107 B
Overall change 14.1 kB 14.1 kB
Client Build Manifests
vercel/next.js canary ctjlewis/next.js isolate-component-requires Change
_buildManifest.js gzip 459 B 459 B
Overall change 459 B 459 B
Rendered Page Sizes
vercel/next.js canary ctjlewis/next.js isolate-component-requires Change
index.html gzip 530 B 530 B
link.html gzip 544 B 544 B
withRouter.html gzip 525 B 525 B
Overall change 1.6 kB 1.6 kB

Default Build with SWC (Decrease detected ✓)
General Overall increase ⚠️
vercel/next.js canary ctjlewis/next.js isolate-component-requires Change
buildDuration 15.7s 15.9s ⚠️ +240ms
buildDurationCached 3.1s 3.2s ⚠️ +33ms
nodeModulesSize 354 MB 354 MB ⚠️ +1.18 kB
Page Load Tests Overall decrease ⚠️
vercel/next.js canary ctjlewis/next.js isolate-component-requires Change
/ failed reqs 0 0
/ total time (seconds) 2.903 8.468 ⚠️ +5.57
/ avg req/sec 861.1 295.24 ⚠️ -565.86
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.281 7.904 ⚠️ +6.62
/error-in-render avg req/sec 1952.07 316.29 ⚠️ -1635.78
Client Bundles (main, webpack, commons)
vercel/next.js canary ctjlewis/next.js isolate-component-requires Change
450.HASH.js gzip 179 B 179 B
framework-HASH.js gzip 42.3 kB 42.3 kB
main-HASH.js gzip 27.3 kB 27.3 kB
webpack-HASH.js gzip 1.44 kB 1.44 kB
Overall change 71.2 kB 71.2 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary ctjlewis/next.js isolate-component-requires Change
polyfills-HASH.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary ctjlewis/next.js isolate-component-requires Change
_app-HASH.js gzip 1.35 kB 1.35 kB
_error-HASH.js gzip 180 B 180 B
amp-HASH.js gzip 305 B 305 B
css-HASH.js gzip 321 B 321 B
dynamic-HASH.js gzip 2.36 kB 2.36 kB
head-HASH.js gzip 342 B 342 B
hooks-HASH.js gzip 906 B 906 B
image-HASH.js gzip 4.72 kB 4.72 kB
index-HASH.js gzip 256 B 256 B
link-HASH.js gzip 2.19 kB 2.19 kB
routerDirect..HASH.js gzip 314 B 314 B
script-HASH.js gzip 375 B 375 B
withRouter-HASH.js gzip 309 B 309 B
85e02e95b279..7e3.css gzip 107 B 107 B
Overall change 14 kB 14 kB
Client Build Manifests
vercel/next.js canary ctjlewis/next.js isolate-component-requires Change
_buildManifest.js gzip 458 B 458 B
Overall change 458 B 458 B
Rendered Page Sizes
vercel/next.js canary ctjlewis/next.js isolate-component-requires Change
index.html gzip 531 B 531 B
link.html gzip 544 B 544 B
withRouter.html gzip 526 B 526 B
Overall change 1.6 kB 1.6 kB
Commit: 5351f69

@ctjlewis
Copy link
Contributor Author

Stats from current PR

Default Build (Decrease detected ✓)

General Overall increase
vercel/next.js canary ctjlewis/next.js isolate-component-requires Change
buildDuration 13.9s 14.1s +157ms
buildDurationCached 3.1s 3.2s +31ms
nodeModulesSize 354 MB 354 MB +1.18 kB
Page Load Tests Overall decrease
vercel/next.js canary ctjlewis/next.js isolate-component-requires Change
/ failed reqs 0 0 ✓
/ total time (seconds) 2.872 7.934 +5.06
/ avg req/sec 870.34 315.12 -555.22
/error-in-render failed reqs 0 0 ✓
/error-in-render total time (seconds) 1.325 8.527 +7.2
/error-in-render avg req/sec 1886.33 293.2 -1593.13
Client Bundles (main, webpack, commons)
Legacy Client Bundles (polyfills)
Client Pages
Client Build Manifests
Rendered Page Sizes
Default Build with SWC (Decrease detected ✓)
Commit: 5351f69

Pretty tough hit to render speed.

@ijjk ijjk force-pushed the canary branch 3 times, most recently from df8579c to 47e5ebe Compare October 25, 2022 16:15
@ijjk ijjk force-pushed the canary branch 2 times, most recently from e078ebe to 6b863fe Compare December 2, 2022 05:49
Copy link
Member

@ijjk ijjk left a comment

Choose a reason for hiding this comment

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

Closing as stale, feel free to open a new discussion if this is still a concern!

@ijjk ijjk closed this Jun 15, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants