Unverified Commit cf7f707f authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Remove PropTypes from _error and next/dynamic (#6763)

* Remove proptypes

* Remove loadable capture in favor of React.createContext

* Add loadable context file

* Make sure we use the context value instead
parent e95030b5
/**
@copyright (c) 2017-present James Kyle <me@thejameskyle.com>
MIT License
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
*/
// https://github.com/jamiebuilds/react-loadable/blob/v5.5.0/src/index.js
// Just the `Capture` class which is only used with SSR
import React from 'react'
import PropTypes from 'prop-types'
type Props = {
report: (moduleName: string) => void
}
export default class Capture extends React.Component<Props> {
static propTypes = {
report: PropTypes.func.isRequired
};
static childContextTypes = {
loadable: PropTypes.shape({
report: PropTypes.func.isRequired
}).isRequired
};
getChildContext () {
return {
loadable: {
report: this.props.report
}
}
}
render () {
return React.Children.only(this.props.children)
}
}
import * as React from 'react'
type CaptureFn = (moduleName: string) => void
// @ts-ignore for some reason the React types don't like this, but it's correct.
export const LoadableContext: React.Context<CaptureFn | null> = React.createContext(null)
...@@ -22,7 +22,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE ...@@ -22,7 +22,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
// Modified to be compatible with webpack 4 / Next.js // Modified to be compatible with webpack 4 / Next.js
import React from 'react' import React from 'react'
import PropTypes from 'prop-types' import { LoadableContext } from './loadable-context'
const ALL_INITIALIZERS = [] const ALL_INITIALIZERS = []
const READY_INITIALIZERS = [] const READY_INITIALIZERS = []
...@@ -161,25 +161,21 @@ function createLoadableComponent (loadFn, options) { ...@@ -161,25 +161,21 @@ function createLoadableComponent (loadFn, options) {
} }
} }
static contextTypes = {
loadable: PropTypes.shape({
report: PropTypes.func.isRequired
})
};
static preload () { static preload () {
return init() return init()
} }
static contextType = LoadableContext
componentWillMount () { componentWillMount () {
this._mounted = true this._mounted = true
this._loadModule() this._loadModule()
} }
_loadModule () { _loadModule () {
if (this.context.loadable && Array.isArray(opts.modules)) { if (this.context && Array.isArray(opts.modules)) {
opts.modules.forEach(moduleName => { opts.modules.forEach(moduleName => {
this.context.loadable.report(moduleName) this.context(moduleName)
}) })
} }
......
...@@ -8,7 +8,7 @@ import mitt, {MittEmitter} from '../lib/mitt'; ...@@ -8,7 +8,7 @@ import mitt, {MittEmitter} from '../lib/mitt';
import { loadGetInitialProps, isResSent } from '../lib/utils' import { loadGetInitialProps, isResSent } from '../lib/utils'
import Head, { defaultHead } from '../lib/head' import Head, { defaultHead } from '../lib/head'
import Loadable from '../lib/loadable' import Loadable from '../lib/loadable'
import LoadableCapture from '../lib/loadable-capture' import {LoadableContext} from '../lib/loadable-context'
import { import {
getDynamicImportBundles, getDynamicImportBundles,
Manifest as ReactLoadableManifest, Manifest as ReactLoadableManifest,
...@@ -292,15 +292,15 @@ export async function renderToHTML( ...@@ -292,15 +292,15 @@ export async function renderToHTML(
return render( return render(
renderElementToString, renderElementToString,
<IsAmpContext.Provider value={amphtml}> <IsAmpContext.Provider value={amphtml}>
<LoadableCapture <LoadableContext.Provider
report={(moduleName) => reactLoadableModules.push(moduleName)} value={(moduleName) => reactLoadableModules.push(moduleName)}
> >
<EnhancedApp <EnhancedApp
Component={EnhancedComponent} Component={EnhancedComponent}
router={router} router={router}
{...props} {...props}
/> />
</LoadableCapture> </LoadableContext.Provider>
</IsAmpContext.Provider>, </IsAmpContext.Provider>,
) )
} }
......
import React from 'react' import React from 'react'
import PropTypes from 'prop-types'
import Head from 'next-server/head' import Head from 'next-server/head'
const statusCodes = { const statusCodes = {
...@@ -45,12 +44,6 @@ export default class Error extends React.Component { ...@@ -45,12 +44,6 @@ export default class Error extends React.Component {
} }
} }
if (process.env.NODE_ENV !== 'production') {
Error.propTypes = {
statusCode: PropTypes.number
}
}
const styles = { const styles = {
error: { error: {
color: '#000', color: '#000',
......
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