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

[examples] Update styled-components to use SWC #34770

Merged
merged 11 commits into from Mar 2, 2022

Conversation

Skagoo
Copy link
Contributor

@Skagoo Skagoo commented Feb 24, 2022

Since Next.js 12.1 we have improved SWC support, which removes the dependency of Babel to work with Styled Components within Next.js.

This PR:

  • updates relavant documentation and references, including to old examples
  • renames an existing example with-styled-components (using Babel) to with-styled-components-babel
  • updates and existing example with-typescript-styled-components combining TypeScript and Styled Components to work with SWC
  • provides a new example with-styled-components using SWC instead of Babel

examples/with-styled-components-babel/README.md Outdated Show resolved Hide resolved
examples/with-styled-components/README.md Outdated Show resolved Hide resolved
examples/with-styled-components-babel/README.md Outdated Show resolved Hide resolved
Copy link
Member

@leerob leerob left a comment

Choose a reason for hiding this comment

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

Thank you so much! This is looking great. One last change.

@ijjk

This comment has been minimized.

remove Notes section since it describes a workaround which is no longer
required to work with `next/link`.
@Skagoo
Copy link
Contributor Author

Skagoo commented Feb 25, 2022

Great, I removed the notes section as requested for the with-styled-components-babel example
Commit: 98a0650

@Skagoo Skagoo requested a review from leerob February 25, 2022 09:22
@leerob leerob changed the title Styled components swc [examples] Update styled-components to use SWC Feb 26, 2022
@ijjk

This comment has been minimized.

@ijjk
Copy link
Member

ijjk commented Feb 26, 2022

Failing test suites

Commit: 503bbbc

yarn testheadless test/integration/image-component/default/test/index.test.js

  • Image Component Tests > dev mode > should warn at most once even after state change
  • Image Component Tests > dev mode > should be valid W3C HTML
  • Image Component Tests > server mode > should be valid W3C HTML
Expand output

● Image Component Tests › dev mode › should warn at most once even after state change

expect(received).toMatch(expected)

Matcher error: received value must be a string

Received has value: undefined

  838 |         'Image with src "/test.png" has "sizes" property but it will be ignored.'
  839 |       )
> 840 |       expect(warnings[1]).toMatch(
      |                           ^
  841 |         'Image with src "/test.png" was detected as the Largest Contentful Paint (LCP).'
  842 |       )
  843 |       expect(warnings.length).toBe(2)

  at Object.<anonymous> (integration/image-component/default/test/index.test.js:840:27)

● Image Component Tests › dev mode › should be valid W3C HTML

Validator returned unexpected statuscode: 503

  at Request._callback (../node_modules/html-validator/lib/w3c-validator.js:15:23)
  at Request.self.callback (../node_modules/request/request.js:185:22)
  at Request.<anonymous> (../node_modules/request/request.js:1154:10)
  at IncomingMessage.<anonymous> (../node_modules/request/request.js:1076:12)

● Image Component Tests › server mode › should be valid W3C HTML

Validator returned unexpected statuscode: 503

  at Request._callback (../node_modules/html-validator/lib/w3c-validator.js:15:23)
  at Request.self.callback (../node_modules/request/request.js:185:22)
  at Request.<anonymous> (../node_modules/request/request.js:1154:10)
  at IncomingMessage.<anonymous> (../node_modules/request/request.js:1076:12)

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

@Skagoo
Copy link
Contributor Author

Skagoo commented Mar 1, 2022

What's the status on this? Are any changes required for my part?

@balazsorban44
Copy link
Member

There have been a few flaky tests that are fixed, if tests will pass again, this should be merged automatically now. 👍

@ijjk
Copy link
Member

ijjk commented Mar 1, 2022

Stats from current PR

Default Build (Increase detected ⚠️)
General Overall decrease ✓
vercel/next.js canary Skagoo/next.js styled-components-swc Change
buildDuration 19.4s 19.5s ⚠️ +133ms
buildDurationCached 7.5s 7.6s ⚠️ +104ms
nodeModulesSize 372 MB 372 MB -14 B
Page Load Tests Overall increase ✓
vercel/next.js canary Skagoo/next.js styled-components-swc Change
/ failed reqs 0 0
/ total time (seconds) 4.268 4.198 -0.07
/ avg req/sec 585.71 595.46 +9.75
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 2.017 2.005 -0.01
/error-in-render avg req/sec 1239.46 1247.1 +7.64
Client Bundles (main, webpack)
vercel/next.js canary Skagoo/next.js styled-components-swc Change
450.HASH.js gzip 179 B 179 B
framework-HASH.js gzip 42 kB 42 kB
main-HASH.js gzip 27.9 kB 27.9 kB
webpack-HASH.js gzip 1.44 kB 1.44 kB
Overall change 71.5 kB 71.5 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary Skagoo/next.js styled-components-swc Change
polyfills-HASH.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary Skagoo/next.js styled-components-swc Change
_app-HASH.js gzip 1.36 kB 1.36 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.57 kB 2.57 kB
head-HASH.js gzip 350 B 350 B
hooks-HASH.js gzip 919 B 919 B
image-HASH.js gzip 5.05 kB 5.05 kB
index-HASH.js gzip 263 B 263 B
link-HASH.js gzip 2.26 kB 2.26 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.7 kB 14.7 kB
Client Build Manifests
vercel/next.js canary Skagoo/next.js styled-components-swc Change
_buildManifest.js gzip 459 B 459 B
Overall change 459 B 459 B
Rendered Page Sizes
vercel/next.js canary Skagoo/next.js styled-components-swc 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

Default Build with SWC (Increase detected ⚠️)
General Overall decrease ✓
vercel/next.js canary Skagoo/next.js styled-components-swc Change
buildDuration 24.3s 24.5s ⚠️ +178ms
buildDurationCached 7.8s 7.5s -327ms
nodeModulesSize 372 MB 372 MB -14 B
Page Load Tests Overall increase ✓
vercel/next.js canary Skagoo/next.js styled-components-swc Change
/ failed reqs 0 0
/ total time (seconds) 4.261 4.19 -0.07
/ avg req/sec 586.65 596.62 +9.97
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 2.035 1.99 -0.05
/error-in-render avg req/sec 1228.3 1256.05 +27.75
Client Bundles (main, webpack)
vercel/next.js canary Skagoo/next.js styled-components-swc Change
450.HASH.js gzip 179 B 179 B
framework-HASH.js gzip 42.3 kB 42.3 kB
main-HASH.js gzip 28.1 kB 28.1 kB
webpack-HASH.js gzip 1.45 kB 1.45 kB
Overall change 72.1 kB 72.1 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary Skagoo/next.js styled-components-swc Change
polyfills-HASH.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary Skagoo/next.js styled-components-swc Change
_app-HASH.js gzip 1.36 kB 1.36 kB
_error-HASH.js gzip 180 B 180 B
amp-HASH.js gzip 313 B 313 B
css-HASH.js gzip 326 B 326 B
dynamic-HASH.js gzip 2.56 kB 2.56 kB
head-HASH.js gzip 350 B 350 B
hooks-HASH.js gzip 921 B 921 B
image-HASH.js gzip 5.2 kB 5.2 kB
index-HASH.js gzip 261 B 261 B
link-HASH.js gzip 2.33 kB 2.33 kB
routerDirect..HASH.js gzip 321 B 321 B
script-HASH.js gzip 386 B 386 B
withRouter-HASH.js gzip 317 B 317 B
85e02e95b279..7e3.css gzip 107 B 107 B
Overall change 14.9 kB 14.9 kB
Client Build Manifests
vercel/next.js canary Skagoo/next.js styled-components-swc Change
_buildManifest.js gzip 456 B 456 B
Overall change 456 B 456 B
Rendered Page Sizes
vercel/next.js canary Skagoo/next.js styled-components-swc Change
index.html gzip 530 B 530 B
link.html gzip 543 B 543 B
withRouter.html gzip 527 B 527 B
Overall change 1.6 kB 1.6 kB
Commit: 80a6bc9

@balazsorban44 balazsorban44 merged commit b579a35 into vercel:canary Mar 2, 2022
@dawidk92
Copy link

dawidk92 commented Mar 3, 2022

@Skagoo @leerob @balazsorban44 I found a bug. When you run build and then start it doesn't have pre-rendered styles. Especially you can see this when you disable javascript through dev tools - it shows plain HTML without styles

@Skagoo
Copy link
Contributor Author

Skagoo commented Mar 3, 2022

@dawidk92 I completely overlooked this, my bad. I did take a look now and I'm quite doubtfull (according to docs) that I missed something in the example setup.
I did some tests using the styledComponents flag under experimental too, with the same results.

Do we have tests that prove the correct/working implementation of how SWC handles the SSR of StyledComponents?

@chemicalkosek
Copy link
Contributor

chemicalkosek commented Mar 8, 2022

Why was custom _document.js deleted from this example?
I have tested swc with styled-components without _document.js and I see FOUC (Flash of unstyled content).
I don't see that happening when there's _document.js

I have created a PR to fix that: #35163

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
examples Issue/PR related to examples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants