未验证 提交 327f6eed 编写于 作者: T Tim Neutkens 提交者: GitHub

Clean up plugins (#14676)

Preparation for a larger rewrite
上级 83de3423
{
"name": "@next/plugin-material-ui",
"version": "9.4.5-canary.22",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-material-ui"
},
"nextjs": {
"name": "Material UI",
"required-env": []
},
"peerDependencies": {
"@material-ui/styles": "*",
"next": "*",
"react": "*"
}
}
# Unstable @next/plugin-material-ui
This package is still very experimental and should not be used at this point
import React from 'react'
export default async function headTags() {
return (
<>
<meta charSet="utf-8" />
<meta
name="viewport"
content="minimum-scale=1, initial-scale=1, width=device-width, shrink-to-fit=no"
/>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"
/>
</>
)
}
import React from 'react'
import { ServerStyleSheets } from '@material-ui/styles'
export default async function enhanceApp(ctx) {
ctx.sheets = new ServerStyleSheets()
return (App) => (props) => ctx.sheets.collect(<App {...props} />)
}
export default async function getStyles(ctx) {
return ctx.sheets.getStyleElement()
}
export default async function unstablePostHydration() {
// Remove the server-side injected CSS.
const jssStyles = document.querySelector('#jss-server-side')
if (jssStyles) {
jssStyles.parentNode.removeChild(jssStyles)
}
}
......@@ -24,9 +24,6 @@ export const VALID_MIDDLEWARE = [
'on-error-client',
'on-error-server',
'babel-preset-build',
'unstable-post-hydration',
'unstable-get-styles-server',
'unstable-enhance-app-server',
]
type ENV_OPTIONS = { [name: string]: string }
......
......@@ -79,20 +79,6 @@ class Container extends React.Component {
componentDidMount() {
this.scrollToHash()
if (process.env.__NEXT_PLUGINS) {
// eslint-disable-next-line
import('next-plugin-loader?middleware=unstable-post-hydration!')
.then((mod) => {
return mod.default()
})
.catch((postHydrationErr) => {
console.error(
'Error calling post-hydration for plugins',
postHydrationErr
)
})
}
// We need to replace the router state if:
// - the page was (auto) exported and has a query string or search (hash)
// - it was auto exported and is a dynamic route (to provide params)
......
......@@ -56,30 +56,12 @@ export default class Document<P = {}> extends Component<DocumentProps & P> {
static async getInitialProps(
ctx: DocumentContext
): Promise<DocumentInitialProps> {
const enhancers = process.env.__NEXT_PLUGINS
? await import(
// @ts-ignore loader syntax
'next-plugin-loader?middleware=unstable-enhance-app-server!'
).then((mod) => mod.default(ctx))
: []
const enhanceApp = (App: any) => {
for (const enhancer of enhancers) {
App = enhancer(App)
}
return (props: any) => <App {...props} />
}
const { html, head } = await ctx.renderPage({ enhanceApp })
const styles = [
...flush(),
...(process.env.__NEXT_PLUGINS
? await import(
// @ts-ignore loader syntax
'next-plugin-loader?middleware=unstable-get-styles-server!'
).then((mod) => mod.default(ctx))
: []),
]
const styles = [...flush()]
return { html, head, styles }
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册