Unverified Commit 6627f57b authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

[Fast Refresh] Upgrade `react-refresh` for SC (#12627)

parent 547bf460
...@@ -100,6 +100,7 @@ ...@@ -100,6 +100,7 @@
"selenium-standalone": "6.17.0", "selenium-standalone": "6.17.0",
"selenium-webdriver": "4.0.0-alpha.5", "selenium-webdriver": "4.0.0-alpha.5",
"shell-quote": "1.7.2", "shell-quote": "1.7.2",
"styled-components": "5.1.0",
"tailwindcss": "1.1.3", "tailwindcss": "1.1.3",
"taskr": "1.1.0", "taskr": "1.1.0",
"tree-kill": "1.2.1", "tree-kill": "1.2.1",
......
This diff is collapsed.
...@@ -96,7 +96,7 @@ ...@@ -96,7 +96,7 @@
"prop-types": "15.7.2", "prop-types": "15.7.2",
"prop-types-exact": "1.2.0", "prop-types-exact": "1.2.0",
"react-is": "16.8.6", "react-is": "16.8.6",
"react-refresh": "0.8.1", "react-refresh": "0.8.2",
"resolve-url-loader": "3.1.1", "resolve-url-loader": "3.1.1",
"sass-loader": "8.0.2", "sass-loader": "8.0.2",
"schema-utils": "2.6.6", "schema-utils": "2.6.6",
......
...@@ -19,11 +19,11 @@ ...@@ -19,11 +19,11 @@
"build": "tsc -d -w -p tsconfig.json" "build": "tsc -d -w -p tsconfig.json"
}, },
"peerDependencies": { "peerDependencies": {
"react-refresh": "0.8.1", "react-refresh": "0.8.2",
"webpack": "^4" "webpack": "^4"
}, },
"devDependencies": { "devDependencies": {
"react-refresh": "0.8.1", "react-refresh": "0.8.2",
"webpack": "^4.42.1" "webpack": "^4.42.1"
} }
} }
/* global jasmine */
/* eslint-env jest */
import { sandbox } from './helpers'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5
// https://github.com/zeit/next.js/issues/12422
test('styled-components hydration mismatch', async () => {
const files = new Map()
files.set(
'pages/_document.js',
`
import Document from 'next/document'
import { ServerStyleSheet } from 'styled-components'
export default class MyDocument extends Document {
static async getInitialProps(ctx) {
const sheet = new ServerStyleSheet()
const originalRenderPage = ctx.renderPage
try {
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: App => props => sheet.collectStyles(<App {...props} />),
})
const initialProps = await Document.getInitialProps(ctx)
return {
...initialProps,
styles: (
<>
{initialProps.styles}
{sheet.getStyleElement()}
</>
),
}
} finally {
sheet.seal()
}
}
}
`
)
const [session, cleanup] = await sandbox(undefined, files)
// We start here.
const didSsr = !(await session.patch(
'index.js',
`
import React from 'react'
import styled from 'styled-components'
const Title = styled.h1\`
color: red;
font-size: 50px;
\`
export default () => <Title>My page</Title>
`
))
// Verify loaded from server:
expect(didSsr).toBe(true)
// Verify no hydration mismatch:
expect(await session.hasRedbox()).toBe(false)
await cleanup()
})
...@@ -6,7 +6,7 @@ import path from 'path' ...@@ -6,7 +6,7 @@ import path from 'path'
const rootSandboxDirectory = path.join(__dirname, '__tmp__') const rootSandboxDirectory = path.join(__dirname, '__tmp__')
export async function sandbox(id = nanoid()) { export async function sandbox(id = nanoid(), initialFiles = new Map()) {
const sandboxDirectory = path.join(rootSandboxDirectory, id) const sandboxDirectory = path.join(rootSandboxDirectory, id)
const pagesDirectory = path.join(sandboxDirectory, 'pages') const pagesDirectory = path.join(sandboxDirectory, 'pages')
...@@ -21,6 +21,9 @@ export async function sandbox(id = nanoid()) { ...@@ -21,6 +21,9 @@ export async function sandbox(id = nanoid()) {
path.join(sandboxDirectory, 'index.js'), path.join(sandboxDirectory, 'index.js'),
`export default () => 'new sandbox';` `export default () => 'new sandbox';`
) )
for (const [k, v] of initialFiles.entries()) {
await fs.writeFile(path.join(sandboxDirectory, k), v)
}
const appPort = await findPort() const appPort = await findPort()
const app = await launchApp(sandboxDirectory, appPort) const app = await launchApp(sandboxDirectory, appPort)
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment