Unverified Commit 13e423cc authored by Balázs Orbán's avatar Balázs Orbán Committed by GitHub

chore: fix examples (#40395)

Closes #40366

Rebass is not dependent on `styled-components` anymore. See:
https://rebassjs.org/migrating/#v4-breaking-changes

Closes #40367

Document has been converted (#39871) from class, so `this.props` threw
an error.

## 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 by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
parent a3a20dcb
{
"presets": ["next/babel"],
"plugins": [
[
"styled-components",
{ "ssr": true, "displayName": true, "preprocess": false }
]
]
}
......@@ -7,14 +7,7 @@
},
"dependencies": {
"next": "latest",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"rebass": "^4.0.7",
"styled-components": "^5.3.0"
},
"devDependencies": {
"babel-plugin-styled-components": "^2.0.7",
"babel-plugin-transform-object-assign": "^6.22.0",
"babel-plugin-transform-object-set-prototype-of-to-assign": "^6.22.0"
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
}
import { Html, Head, Main, NextScript } from 'next/document'
import { ServerStyleSheet } from 'styled-components'
export default function Document() {
const sheet = new ServerStyleSheet()
const main = sheet.collectStyles(<Main />)
const styleTags = sheet.getStyleElement()
return (
<Html>
<Head>{styleTags}</Head>
<body>
<div className="root">{main}</div>
<NextScript />
</body>
</Html>
)
}
......@@ -6,13 +6,13 @@ const cspHashOf = (text) => {
hash.update(text)
return `'sha256-${hash.digest('base64')}'`
}
export default function Document() {
export default function Document(ctx) {
let csp = `default-src 'self'; script-src 'self' ${cspHashOf(
NextScript.getInlineScriptSource(this.props)
NextScript.getInlineScriptSource(ctx)
)}`
if (process.env.NODE_ENV !== 'production') {
csp = `style-src 'self' 'unsafe-inline'; font-src 'self' data:; default-src 'self'; script-src 'unsafe-eval' 'self' ${cspHashOf(
NextScript.getInlineScriptSource(this.props)
NextScript.getInlineScriptSource(ctx)
)}`
}
......
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