Skip to content

Commit c53600a

Browse files
Merge branch 'canary' into fix-19074
2 parents 9d5d787 + f1e6bc9 commit c53600a

File tree

8 files changed

+86
-19
lines changed

8 files changed

+86
-19
lines changed

packages/next/client/script.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ import { requestIdleCallback } from './request-idle-callback'
77
const ScriptCache = new Map()
88
const LoadCache = new Set()
99

10-
export interface Props extends ScriptHTMLAttributes<HTMLScriptElement> {
10+
export interface ScriptProps extends ScriptHTMLAttributes<HTMLScriptElement> {
1111
strategy?: 'afterInteractive' | 'lazyOnload' | 'beforeInteractive'
1212
id?: string
1313
onLoad?: () => void
1414
onError?: () => void
1515
children?: React.ReactNode
1616
}
1717

18+
/**
19+
* @deprecated Use `ScriptProps` instead.
20+
*/
21+
export type Props = ScriptProps
22+
1823
const ignoreProps = [
1924
'onLoad',
2025
'dangerouslySetInnerHTML',
@@ -23,7 +28,7 @@ const ignoreProps = [
2328
'strategy',
2429
]
2530

26-
const loadScript = (props: Props): void => {
31+
const loadScript = (props: ScriptProps): void => {
2732
const {
2833
src,
2934
id,
@@ -90,7 +95,7 @@ const loadScript = (props: Props): void => {
9095
document.body.appendChild(el)
9196
}
9297

93-
function handleClientScriptLoad(props: Props) {
98+
function handleClientScriptLoad(props: ScriptProps) {
9499
const { strategy = 'afterInteractive' } = props
95100
if (strategy === 'afterInteractive') {
96101
loadScript(props)
@@ -101,7 +106,7 @@ function handleClientScriptLoad(props: Props) {
101106
}
102107
}
103108

104-
function loadLazyScript(props: Props) {
109+
function loadLazyScript(props: ScriptProps) {
105110
if (document.readyState === 'complete') {
106111
requestIdleCallback(() => loadScript(props))
107112
} else {
@@ -111,11 +116,11 @@ function loadLazyScript(props: Props) {
111116
}
112117
}
113118

114-
export function initScriptLoader(scriptLoaderItems: Props[]) {
119+
export function initScriptLoader(scriptLoaderItems: ScriptProps[]) {
115120
scriptLoaderItems.forEach(handleClientScriptLoad)
116121
}
117122

118-
function Script(props: Props): JSX.Element | null {
123+
function Script(props: ScriptProps): JSX.Element | null {
119124
const {
120125
src = '',
121126
onLoad = () => {},

packages/next/pages/_document.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import { BuildManifest, getPageFiles } from '../server/get-page-files'
1515
import { cleanAmpPath } from '../server/utils'
1616
import { htmlEscapeJsonString } from '../server/htmlescape'
17-
import Script, { Props as ScriptLoaderProps } from '../client/script'
17+
import Script, { ScriptProps } from '../client/script'
1818

1919
export { DocumentContext, DocumentInitialProps, DocumentProps }
2020

@@ -76,7 +76,7 @@ function getPreNextScripts(context: DocumentProps, props: OriginProps) {
7676
const { scriptLoader, disableOptimizedLoading } = context
7777

7878
return (scriptLoader.beforeInteractive || []).map(
79-
(file: ScriptLoaderProps, index: number) => {
79+
(file: ScriptProps, index: number) => {
8080
const { strategy, ...scriptProps } = file
8181
return (
8282
<script
@@ -408,7 +408,7 @@ export class Head extends Component<
408408

409409
handleDocumentScriptLoaderItems(children: React.ReactNode): ReactNode[] {
410410
const { scriptLoader } = this.context
411-
const scriptLoaderItems: ScriptLoaderProps[] = []
411+
const scriptLoaderItems: ScriptProps[] = []
412412
const filteredChildren: ReactNode[] = []
413413

414414
React.Children.forEach(children, (child: any) => {

test/.stats-app/image.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Image from 'next/image'
2+
import logo from './nextjs.png'
3+
4+
function ImagePage(props) {
5+
return (
6+
<>
7+
<h1>next/image example</h1>
8+
<Image src={logo} placeholder="blur" />
9+
</>
10+
)
11+
}
12+
13+
// we add getServerSideProps to prevent static optimization
14+
// to allow us to compare server-side changes
15+
export const getServerSideProps = () => {
16+
return {
17+
props: {},
18+
}
19+
}
20+
21+
export default ImagePage

test/.stats-app/pages/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
const Page = () => 'Hello world 👋'
22

3-
Page.getInitialProps = () => ({})
3+
// we add getServerSideProps to prevent static optimization
4+
// to allow us to compare server-side changes
5+
export const getServerSideProps = () => {
6+
return {
7+
props: {},
8+
}
9+
}
410

511
export default Page

test/.stats-app/pages/link.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ function aLink(props) {
99
)
1010
}
1111

12-
aLink.getInitialProps = () => ({})
12+
// we add getServerSideProps to prevent static optimization
13+
// to allow us to compare server-side changes
14+
export const getServerSideProps = () => {
15+
return {
16+
props: {},
17+
}
18+
}
1319

1420
export default aLink

test/.stats-app/pages/routerDirect.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ function routerDirect(props) {
55
return <div>I import the router directly</div>
66
}
77

8-
routerDirect.getInitialProps = () => ({})
8+
// we add getServerSideProps to prevent static optimization
9+
// to allow us to compare server-side changes
10+
export const getServerSideProps = () => {
11+
return {
12+
props: {},
13+
}
14+
}
915

1016
export default routerDirect

test/.stats-app/pages/withRouter.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ function useWithRouter(props) {
44
return <div>I use withRouter</div>
55
}
66

7-
useWithRouter.getInitialProps = () => ({})
7+
// we add getServerSideProps to prevent static optimization
8+
// to allow us to compare server-side changes
9+
export const getServerSideProps = () => {
10+
return {
11+
props: {},
12+
}
13+
}
814

915
export default withRouter(useWithRouter)

test/.stats-app/stats-config.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
// this page is conditionally added when not testing
4+
// in webpack 4 mode since it's not supported for webpack 4
5+
const imagePageData = fs.readFileSync(
6+
path.join(__dirname, './image.js'),
7+
'utf8'
8+
)
9+
110
const clientGlobs = [
211
{
312
name: 'Client Bundles (main, webpack, commons)',
@@ -12,11 +21,11 @@ const clientGlobs = [
1221
},
1322
{
1423
name: 'Client Pages',
15-
globs: ['.next/static/*/pages/**/*', '.next/static/css/**/*'],
24+
globs: ['.next/static/BUILD_ID/pages/**/*.js', '.next/static/css/**/*'],
1625
},
1726
{
1827
name: 'Client Build Manifests',
19-
globs: ['.next/static/*/_buildManifest*'],
28+
globs: ['.next/static/BUILD_ID/_buildManifest*'],
2029
},
2130
{
2231
name: 'Rendered Page Sizes',
@@ -26,19 +35,19 @@ const clientGlobs = [
2635

2736
const renames = [
2837
{
29-
srcGlob: '.next/static/*/pages',
38+
srcGlob: '.next/static/chunks/pages',
3039
dest: '.next/static/BUILD_ID/pages',
3140
},
3241
{
33-
srcGlob: '.next/static/*/pages/**/*',
42+
srcGlob: '.next/static/BUILD_ID/pages/**/*.js',
3443
removeHash: true,
3544
},
3645
{
37-
srcGlob: '.next/static/runtime/*',
46+
srcGlob: '.next/static/runtime/*.js',
3847
removeHash: true,
3948
},
4049
{
41-
srcGlob: '.next/static/chunks/*',
50+
srcGlob: '.next/static/chunks/*.js',
4251
removeHash: true,
4352
},
4453
{
@@ -60,6 +69,10 @@ module.exports = {
6069
title: 'Default Build',
6170
diff: 'onOutputChange',
6271
diffConfigFiles: [
72+
{
73+
path: 'pages/image.js',
74+
content: imagePageData,
75+
},
6376
{
6477
path: 'next.config.js',
6578
content: `
@@ -77,6 +90,10 @@ module.exports = {
7790
// renames to apply to make file names deterministic
7891
renames,
7992
configFiles: [
93+
{
94+
path: 'pages/image.js',
95+
content: imagePageData,
96+
},
8097
{
8198
path: 'next.config.js',
8299
content: `

0 commit comments

Comments
 (0)