Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
ccd3df2f
Unverified
Commit
ccd3df2f
authored
Jun 02, 2022
by
Steven
Committed by
GitHub
Jun 02, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bloat in main bundle from amp (#37383)
- Related to #35900 - Related to #36702 - Related to #35907
parent
129052dc
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
28 additions
and
11 deletions
+28
-11
worker.ts
packages/next/export/worker.ts
+1
-1
render.tsx
packages/next/server/render.tsx
+1
-1
amp-mode.ts
packages/next/shared/lib/amp-mode.ts
+7
-0
amp.ts
packages/next/shared/lib/amp.ts
+1
-8
head.tsx
packages/next/shared/lib/head.tsx
+1
-1
index.test.js
test/integration/production/test/index.test.js
+17
-0
No files found.
packages/next/export/worker.ts
View file @
ccd3df2f
...
@@ -19,7 +19,7 @@ import '../server/node-polyfill-fetch'
...
@@ -19,7 +19,7 @@ import '../server/node-polyfill-fetch'
import
{
requireFontManifest
}
from
'../server/require'
import
{
requireFontManifest
}
from
'../server/require'
import
{
normalizeLocalePath
}
from
'../shared/lib/i18n/normalize-locale-path'
import
{
normalizeLocalePath
}
from
'../shared/lib/i18n/normalize-locale-path'
import
{
trace
}
from
'../trace'
import
{
trace
}
from
'../trace'
import
{
isInAmpMode
}
from
'../shared/lib/amp'
import
{
isInAmpMode
}
from
'../shared/lib/amp
-mode
'
import
{
setHttpAgentOptions
}
from
'../server/config'
import
{
setHttpAgentOptions
}
from
'../server/config'
import
RenderResult
from
'../server/render-result'
import
RenderResult
from
'../server/render-result'
import
isError
from
'../lib/is-error'
import
isError
from
'../lib/is-error'
...
...
packages/next/server/render.tsx
View file @
ccd3df2f
...
@@ -43,7 +43,7 @@ import {
...
@@ -43,7 +43,7 @@ import {
STATIC_STATUS_PAGES
,
STATIC_STATUS_PAGES
,
}
from
'../shared/lib/constants'
}
from
'../shared/lib/constants'
import
{
isSerializableProps
}
from
'../lib/is-serializable-props'
import
{
isSerializableProps
}
from
'../lib/is-serializable-props'
import
{
isInAmpMode
}
from
'../shared/lib/amp'
import
{
isInAmpMode
}
from
'../shared/lib/amp
-mode
'
import
{
AmpStateContext
}
from
'../shared/lib/amp-context'
import
{
AmpStateContext
}
from
'../shared/lib/amp-context'
import
{
defaultHead
}
from
'../shared/lib/head'
import
{
defaultHead
}
from
'../shared/lib/head'
import
{
HeadManagerContext
}
from
'../shared/lib/head-manager-context'
import
{
HeadManagerContext
}
from
'../shared/lib/head-manager-context'
...
...
packages/next/shared/lib/amp-mode.ts
0 → 100644
View file @
ccd3df2f
export
function
isInAmpMode
({
ampFirst
=
false
,
hybrid
=
false
,
hasQuery
=
false
,
}
=
{}):
boolean
{
return
ampFirst
||
(
hybrid
&&
hasQuery
)
}
packages/next/shared/lib/amp.ts
View file @
ccd3df2f
import
React
from
'react'
import
React
from
'react'
import
{
AmpStateContext
}
from
'./amp-context'
import
{
AmpStateContext
}
from
'./amp-context'
import
{
isInAmpMode
}
from
'./amp-mode'
export
function
isInAmpMode
({
ampFirst
=
false
,
hybrid
=
false
,
hasQuery
=
false
,
}
=
{}):
boolean
{
return
ampFirst
||
(
hybrid
&&
hasQuery
)
}
export
function
useAmp
():
boolean
{
export
function
useAmp
():
boolean
{
// Don't assign the context value to a variable to save bytes
// Don't assign the context value to a variable to save bytes
...
...
packages/next/shared/lib/head.tsx
View file @
ccd3df2f
...
@@ -2,7 +2,7 @@ import React, { useContext } from 'react'
...
@@ -2,7 +2,7 @@ import React, { useContext } from 'react'
import
Effect
from
'./side-effect'
import
Effect
from
'./side-effect'
import
{
AmpStateContext
}
from
'./amp-context'
import
{
AmpStateContext
}
from
'./amp-context'
import
{
HeadManagerContext
}
from
'./head-manager-context'
import
{
HeadManagerContext
}
from
'./head-manager-context'
import
{
isInAmpMode
}
from
'./amp'
import
{
isInAmpMode
}
from
'./amp
-mode
'
import
{
warnOnce
}
from
'./utils'
import
{
warnOnce
}
from
'./utils'
type
WithInAmpMode
=
{
type
WithInAmpMode
=
{
...
...
test/integration/production/test/index.test.js
View file @
ccd3df2f
...
@@ -313,6 +313,23 @@ describe('Production Usage', () => {
...
@@ -313,6 +313,23 @@ describe('Production Usage', () => {
expect
(
content
).
not
.
toContain
(
'.currentScript'
)
expect
(
content
).
not
.
toContain
(
'.currentScript'
)
})
})
it
(
'should not contain useAmp in main chunk'
,
async
()
=>
{
const
globResult
=
await
glob
(
'main-*.js'
,
{
cwd
:
join
(
appDir
,
'.next/static/chunks'
),
})
if
(
!
globResult
||
globResult
.
length
!==
1
)
{
throw
new
Error
(
'could not find main js chunk'
)
}
const
content
=
await
fs
.
readFile
(
join
(
appDir
,
'.next/static/chunks'
,
globResult
[
0
]),
'utf8'
)
expect
(
content
).
not
.
toContain
(
'useAmp'
)
})
describe
(
'With basic usage'
,
()
=>
{
describe
(
'With basic usage'
,
()
=>
{
it
(
'should render the page'
,
async
()
=>
{
it
(
'should render the page'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/'
)
const
html
=
await
renderViaHTTP
(
appPort
,
'/'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment