-
Notifications
You must be signed in to change notification settings - Fork 27.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'canary' of https://github.com/vercel/next.js into font-…
…defaults
- Loading branch information
Showing
49 changed files
with
851 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Missing webpack config | ||
|
||
#### Why This Error Occurred | ||
|
||
The value returned from the custom `webpack` function in your `next.config.js` was undefined. This can occur from the initial config value not being returned. | ||
|
||
#### Possible Ways to Fix It | ||
|
||
Make sure to return the `webpack` config from your custom `webpack` function in your `next.config.js` | ||
|
||
```js | ||
// next.config.js | ||
|
||
module.exports = { | ||
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => { | ||
// Note: we provide webpack above so you should not `require` it | ||
// Perform customizations to webpack config | ||
config.plugins.push(new webpack.IgnorePlugin(/\/__tests__\//)) | ||
|
||
// Important: return the modified config | ||
return config | ||
}, | ||
} | ||
``` | ||
|
||
### Useful Links | ||
|
||
- [Custom webpack config Documentation](https://nextjs.org/docs/api-reference/next.config.js/custom-webpack-config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
/out/ | ||
|
||
# production | ||
/build | ||
/dist | ||
|
||
# misc | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,5 @@ | |
"registry": "https://registry.npmjs.org/" | ||
} | ||
}, | ||
"version": "10.0.3" | ||
"version": "10.0.4-canary.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "create-next-app", | ||
"version": "10.0.3", | ||
"version": "10.0.4-canary.1", | ||
"keywords": [ | ||
"react", | ||
"next", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@next/env", | ||
"version": "10.0.3", | ||
"version": "10.0.4-canary.1", | ||
"keywords": [ | ||
"react", | ||
"next", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import React, { useEffect, useContext } from 'react' | ||
import { ScriptHTMLAttributes } from 'react' | ||
import { HeadManagerContext } from '../next-server/lib/head-manager-context' | ||
import { DOMAttributeNames } from './head-manager' | ||
import requestIdleCallback from './request-idle-callback' | ||
|
||
const ScriptCache = new Map() | ||
const LoadCache = new Set() | ||
|
||
interface Props extends ScriptHTMLAttributes<HTMLScriptElement> { | ||
strategy?: 'defer' | 'lazy' | 'dangerouslyBlockRendering' | 'eager' | ||
id?: string | ||
onLoad?: () => void | ||
onError?: () => void | ||
children?: React.ReactNode | ||
preload?: boolean | ||
} | ||
|
||
const loadScript = (props: Props) => { | ||
const { | ||
src = '', | ||
onLoad = () => {}, | ||
dangerouslySetInnerHTML, | ||
children = '', | ||
id, | ||
onError, | ||
} = props | ||
|
||
const cacheKey = id || src | ||
if (ScriptCache.has(src)) { | ||
if (!LoadCache.has(cacheKey)) { | ||
LoadCache.add(cacheKey) | ||
// Execute onLoad since the script loading has begun | ||
ScriptCache.get(src).then(onLoad, onError) | ||
} | ||
return | ||
} | ||
|
||
const el = document.createElement('script') | ||
|
||
const loadPromise = new Promise((resolve, reject) => { | ||
el.addEventListener('load', function () { | ||
resolve() | ||
if (onLoad) { | ||
onLoad.call(this) | ||
} | ||
}) | ||
el.addEventListener('error', function () { | ||
reject() | ||
if (onError) { | ||
onError() | ||
} | ||
}) | ||
}) | ||
|
||
if (src) { | ||
ScriptCache.set(src, loadPromise) | ||
LoadCache.add(cacheKey) | ||
} | ||
|
||
if (dangerouslySetInnerHTML) { | ||
el.innerHTML = dangerouslySetInnerHTML.__html || '' | ||
} else if (children) { | ||
el.textContent = | ||
typeof children === 'string' | ||
? children | ||
: Array.isArray(children) | ||
? children.join('') | ||
: '' | ||
} else if (src) { | ||
el.src = src | ||
} | ||
|
||
for (const [k, value] of Object.entries(props)) { | ||
if (value === undefined) { | ||
continue | ||
} | ||
|
||
const attr = DOMAttributeNames[k] || k.toLowerCase() | ||
el.setAttribute(attr, value) | ||
} | ||
|
||
document.body.appendChild(el) | ||
} | ||
|
||
export default function Script(props: Props) { | ||
const { | ||
src = '', | ||
onLoad = () => {}, | ||
dangerouslySetInnerHTML, | ||
children = '', | ||
strategy = 'defer', | ||
onError, | ||
preload = false, | ||
...restProps | ||
} = props | ||
|
||
// Context is available only during SSR | ||
const { updateScripts, scripts } = useContext(HeadManagerContext) | ||
|
||
useEffect(() => { | ||
if (strategy === 'defer') { | ||
loadScript(props) | ||
} else if (strategy === 'lazy') { | ||
window.addEventListener('load', () => { | ||
requestIdleCallback(() => loadScript(props)) | ||
}) | ||
} | ||
}, [strategy, props]) | ||
|
||
if (strategy === 'dangerouslyBlockRendering') { | ||
const syncProps: Props = { ...restProps } | ||
|
||
for (const [k, value] of Object.entries({ | ||
src, | ||
onLoad, | ||
onError, | ||
dangerouslySetInnerHTML, | ||
children, | ||
})) { | ||
if (!value) { | ||
continue | ||
} | ||
if (k === 'children') { | ||
syncProps.dangerouslySetInnerHTML = { | ||
__html: | ||
typeof value === 'string' | ||
? value | ||
: Array.isArray(value) | ||
? value.join('') | ||
: '', | ||
} | ||
} else { | ||
;(syncProps as any)[k] = value | ||
} | ||
} | ||
|
||
return <script {...syncProps} /> | ||
} else if (strategy === 'defer') { | ||
if (updateScripts && preload) { | ||
scripts.defer = (scripts.defer || []).concat([src]) | ||
updateScripts(scripts) | ||
} | ||
} else if (strategy === 'eager') { | ||
if (updateScripts) { | ||
scripts.eager = (scripts.eager || []).concat([ | ||
{ | ||
src, | ||
onLoad, | ||
onError, | ||
...restProps, | ||
}, | ||
]) | ||
updateScripts(scripts) | ||
} | ||
} | ||
|
||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.