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

Port next-ssg getStaticProps/getServerSideProps tree shaking Babel transform to rust #27552

Merged
merged 92 commits into from
Aug 3, 2021

Conversation

kdy1
Copy link
Member

@kdy1 kdy1 commented Jul 28, 2021

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

Currently, the PR is not ready.

Remaining tasks:

  • swc: Improve codegen.
  • swc: Make testing library usable with stable rust.
  • next-ssg: Preserve unrelated dead code.
  • swc: Provide api to run resolver before custom passes.
  • next-ssg: should support export { _ as default } (test)
  • next-ssg: should support babel-style memoized function (test)
  • next-ssg: destructuring assignment (object) (test)
  • next-ssg: destructuring assignment (array) (test)
  • Inject export var __N_SSG = true to correct position.

I added a rust-side test because debugging rust code with jest is literally impossible.

I need some comments about unit testing. How should it be organized?
I used the existing test suite, but I also added a rust-based testing system.

@ijjk

This comment has been minimized.

@@ -0,0 +1,4 @@
[build]
Copy link
Member Author

Choose a reason for hiding this comment

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

This is temporary. I'll remove this after implementing support for stable rust in testing system of swc.

@@ -0,0 +1 @@
nightly-2021-03-25
Copy link
Member Author

Choose a reason for hiding this comment

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

Same as above. It's temporary, and I think using stable is better.

@@ -172,7 +173,7 @@ fn process_js_custom(
}
};
let config = BuiltConfig {
Copy link
Member Author

Choose a reason for hiding this comment

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

I think we need some way to organize passes properly.

@ijjk

This comment has been minimized.

@timneutkens timneutkens changed the title Port next-ssg to rust Port next-ssg getStaticProps/getServerSideProps tree shaking Babel transform to rust Jul 30, 2021
timneutkens
timneutkens previously approved these changes Aug 2, 2021
Copy link
Member

@timneutkens timneutkens left a comment

Choose a reason for hiding this comment

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

Looks great 🎉

@timneutkens
Copy link
Member

packages/next/build/swc/tests/fixture has to be added to .eslintignore as currently the lint step fails

@padmaia
Copy link
Member

padmaia commented Aug 2, 2021

I think the CI issues actually are related. I was experiencing the same thing when I was trying to open up a PR with the new testing setup on Friday. For some reason the errors are being hidden when running yarn from the root, but you can see this task is failing to build the js files in the fixtures when running yarn in packages/next (thanks to @ijjk for helping me figure this out). The solution would be to tell the task to ignore those files or move the rust code out of build and just keep the binding there.

@kdy1
Copy link
Member Author

kdy1 commented Aug 2, 2021

Thanks! I excluded them.

@ijjk

This comment has been minimized.

@ijjk

This comment has been minimized.

@ijjk

This comment has been minimized.

@ijjk

This comment has been minimized.

@ijjk

This comment has been minimized.

@ijjk

This comment has been minimized.

@ijjk
Copy link
Member

ijjk commented Aug 2, 2021

Failing test suites

Commit: 7c152b7

test/acceptance/ReactRefreshLogBox.dev.test.js

  • server-side only compilation errors

Expand output

● server-side only compilation errors

ScriptTimeoutError: script timeout
  (Session info: headless chrome=92.0.4515.107)

  72 |
  73 |             // Wait for application to re-hydrate:
> 74 |             await browser.executeAsyncScript(function () {
     |             ^
  75 |               var callback = arguments[arguments.length - 1]
  76 |               if (window.__NEXT_HYDRATED) {
  77 |                 callback()

  at Object.throwDecodedError (../node_modules/selenium-webdriver/lib/error.js:550:15)
  at parseHttpResponse (../node_modules/selenium-webdriver/lib/http.js:565:13)
  at Executor.execute (../node_modules/selenium-webdriver/lib/http.js:491:26)
      at runMicrotasks (<anonymous>)
  at Proxy.execute (../node_modules/selenium-webdriver/lib/webdriver.js:700:17)
  at Object.patch (acceptance/helpers.js:74:13)
  at Object.<anonymous> (acceptance/ReactRefreshLogBox.dev.test.js:1415:3)

@ijjk
Copy link
Member

ijjk commented Aug 3, 2021

Stats from current PR

Default Build (Decrease detected ✓)
General Overall increase ⚠️
vercel/next.js canary kdy1/next.js swc-next-ssg Change
buildDuration 13.2s 12.6s -635ms
buildDurationCached 3.1s 3s -131ms
nodeModulesSize 50.1 MB 50.1 MB ⚠️ +10.2 kB
Page Load Tests Overall decrease ⚠️
vercel/next.js canary kdy1/next.js swc-next-ssg Change
/ failed reqs 0 0
/ total time (seconds) 2.291 2.279 -0.01
/ avg req/sec 1091.28 1097.19 +5.91
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.256 1.28 ⚠️ +0.02
/error-in-render avg req/sec 1990.67 1952.99 ⚠️ -37.68
Client Bundles (main, webpack, commons)
vercel/next.js canary kdy1/next.js swc-next-ssg Change
745.HASH.js gzip 179 B 179 B
framework-HASH.js gzip 42.2 kB 42.2 kB
main-HASH.js gzip 22.8 kB 22.8 kB
webpack-HASH.js gzip 1.5 kB 1.5 kB
Overall change 66.7 kB 66.7 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary kdy1/next.js swc-next-ssg Change
polyfills-HASH.js gzip 31.1 kB 31.1 kB
Overall change 31.1 kB 31.1 kB
Client Pages
vercel/next.js canary kdy1/next.js swc-next-ssg Change
_app-HASH.js gzip 980 B 980 B
_error-HASH.js gzip 194 B 194 B
amp-HASH.js gzip 312 B 312 B
css-HASH.js gzip 329 B 329 B
dynamic-HASH.js gzip 2.52 kB 2.52 kB
head-HASH.js gzip 350 B 350 B
hooks-HASH.js gzip 904 B 904 B
image-HASH.js gzip 4.13 kB 4.13 kB
index-HASH.js gzip 261 B 261 B
link-HASH.js gzip 1.66 kB 1.66 kB
routerDirect..HASH.js gzip 319 B 319 B
script-HASH.js gzip 387 B 387 B
withRouter-HASH.js gzip 320 B 320 B
bb14e60e810b..30f.css gzip 125 B 125 B
Overall change 12.8 kB 12.8 kB
Client Build Manifests
vercel/next.js canary kdy1/next.js swc-next-ssg Change
_buildManifest.js gzip 492 B 492 B
Overall change 492 B 492 B
Rendered Page Sizes
vercel/next.js canary kdy1/next.js swc-next-ssg Change
index.html gzip 531 B 531 B
link.html gzip 543 B 543 B
withRouter.html gzip 524 B 524 B
Overall change 1.6 kB 1.6 kB

Webpack 4 Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary kdy1/next.js swc-next-ssg Change
buildDuration 10.2s 10.2s ⚠️ +6ms
buildDurationCached 4.2s 4s -158ms
nodeModulesSize 50.1 MB 50.1 MB ⚠️ +10.2 kB
Page Load Tests Overall increase ✓
vercel/next.js canary kdy1/next.js swc-next-ssg Change
/ failed reqs 0 0
/ total time (seconds) 2.279 2.339 ⚠️ +0.06
/ avg req/sec 1096.79 1069.02 ⚠️ -27.77
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.277 1.213 -0.06
/error-in-render avg req/sec 1957.46 2060.49 +103.03
Client Bundles (main, webpack, commons)
vercel/next.js canary kdy1/next.js swc-next-ssg Change
17.HASH.js gzip 185 B 185 B
677f882d2ed8..HASH.js gzip 13.8 kB 13.8 kB
framework.HASH.js gzip 41.9 kB 41.9 kB
main-HASH.js gzip 10.6 kB 10.6 kB
webpack-HASH.js gzip 1.19 kB 1.19 kB
Overall change 67.7 kB 67.7 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary kdy1/next.js swc-next-ssg Change
polyfills-HASH.js gzip 31.3 kB 31.3 kB
Overall change 31.3 kB 31.3 kB
Client Pages
vercel/next.js canary kdy1/next.js swc-next-ssg Change
_app-HASH.js gzip 965 B 965 B
_error-HASH.js gzip 3.74 kB 3.74 kB
amp-HASH.js gzip 552 B 552 B
css-HASH.js gzip 333 B 333 B
dynamic-HASH.js gzip 2.71 kB 2.71 kB
head-HASH.js gzip 2.97 kB 2.97 kB
hooks-HASH.js gzip 911 B 911 B
index-HASH.js gzip 231 B 231 B
link-HASH.js gzip 1.64 kB 1.64 kB
routerDirect..HASH.js gzip 298 B 298 B
script-HASH.js gzip 2.94 kB 2.94 kB
withRouter-HASH.js gzip 294 B 294 B
e025d2764813..52f.css gzip 125 B 125 B
Overall change 17.7 kB 17.7 kB
Client Build Manifests
vercel/next.js canary kdy1/next.js swc-next-ssg Change
_buildManifest.js gzip 499 B 499 B
Overall change 499 B 499 B
Rendered Page Sizes
vercel/next.js canary kdy1/next.js swc-next-ssg Change
index.html gzip 577 B 577 B
link.html gzip 589 B 589 B
withRouter.html gzip 569 B 569 B
Overall change 1.74 kB 1.74 kB
Commit: 8b619c2

@eric-burel
Copy link
Contributor

eric-burel commented Aug 9, 2021

Hi guys, I am digging this PR because I'm very interested in the ability to have server-side and client-side code mixed in an isomorphic manner, I'd like to use a similar approach to define data models, form inputs, and some API endpoints in one single file.
I have only one question: why the switch to Rust for this particular feature? This doesn't sound like a part of Next.js that requires very strong performance, so I don't get why Babel and some JS would not be sufficient.

flybayer pushed a commit to blitz-js/next.js that referenced this pull request Aug 19, 2021
@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
@kdy1 kdy1 self-assigned this Oct 23, 2024
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.

5 participants