diff --git a/packages/next/build/swc/options.js b/packages/next/build/swc/options.js
index 362ce88a42a55..8e1a5820a350b 100644
--- a/packages/next/build/swc/options.js
+++ b/packages/next/build/swc/options.js
@@ -43,10 +43,7 @@ function getBaseSWCOptions({
},
},
},
- styledComponents: {
- displayName: styledComponents,
- ssr: styledComponents,
- },
+ styledComponents: styledComponents ? {} : null,
}
}
diff --git a/test/development/basic/styled-components-disabled.test.ts b/test/development/basic/styled-components-disabled.test.ts
new file mode 100644
index 0000000000000..af49dd5deb910
--- /dev/null
+++ b/test/development/basic/styled-components-disabled.test.ts
@@ -0,0 +1,65 @@
+import { join } from 'path'
+import webdriver from 'next-webdriver'
+import { createNext, FileRef } from 'e2e-utils'
+import { NextInstance } from 'test/lib/next-modes/base'
+import { fetchViaHTTP } from 'next-test-utils'
+
+describe('styled-components SWC transform', () => {
+ let next: NextInstance
+
+ beforeAll(async () => {
+ next = await createNext({
+ files: {
+ 'next.config.js': new FileRef(
+ join(__dirname, 'styled-components-disabled/next.config.js')
+ ),
+ pages: new FileRef(join(__dirname, 'styled-components-disabled/pages')),
+ },
+ dependencies: {
+ 'styled-components': '5.3.3',
+ },
+ })
+ })
+ afterAll(() => next.destroy())
+
+ async function matchLogs$(browser) {
+ let foundLog = false
+
+ const browserLogs = await browser.log('browser')
+
+ browserLogs.forEach((log) => {
+ if (log.message.includes('Warning: Prop `%s` did not match.')) {
+ foundLog = true
+ }
+ })
+ return foundLog
+ }
+ it('should have hydration mismatch with styled-components transform disabled', async () => {
+ let browser
+ try {
+ browser = await webdriver(next.appPort, '/')
+
+ // Compile /_error
+ await fetchViaHTTP(next.appPort, '/404')
+
+ try {
+ // Try 4 times to be sure there is no mismatch
+ expect(await matchLogs$(browser)).toBe(false)
+ await browser.refresh()
+ expect(await matchLogs$(browser)).toBe(false)
+ await browser.refresh()
+ expect(await matchLogs$(browser)).toBe(false)
+ await browser.refresh()
+ expect(await matchLogs$(browser)).toBe(false)
+ throw new Error('did not find mismatch')
+ } catch (err) {
+ // Verify that it really has the logs
+ expect(await matchLogs$(browser)).toBe(true)
+ }
+ } finally {
+ if (browser) {
+ await browser.close()
+ }
+ }
+ })
+})
diff --git a/test/development/basic/styled-components-disabled/next.config.js b/test/development/basic/styled-components-disabled/next.config.js
new file mode 100644
index 0000000000000..4ba52ba2c8df6
--- /dev/null
+++ b/test/development/basic/styled-components-disabled/next.config.js
@@ -0,0 +1 @@
+module.exports = {}
diff --git a/test/development/basic/styled-components-disabled/pages/_app.js b/test/development/basic/styled-components-disabled/pages/_app.js
new file mode 100644
index 0000000000000..019f78b2afc64
--- /dev/null
+++ b/test/development/basic/styled-components-disabled/pages/_app.js
@@ -0,0 +1,26 @@
+import { createGlobalStyle, ThemeProvider } from 'styled-components'
+
+const GlobalStyle = createGlobalStyle`
+ body {
+ margin: 0;
+ padding: 0;
+ box-sizing: border-box;
+ }
+`
+
+const theme = {
+ colors: {
+ primary: '#0070f3',
+ },
+}
+
+export default function App({ Component, pageProps }) {
+ return (
+ <>
+