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
e6e402e4
Unverified
Commit
e6e402e4
authored
Jan 13, 2021
by
Janicklas Ralph
Committed by
GitHub
Jan 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Font optimization - remove warning message (#20874)
parent
417a7120
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
20 deletions
+9
-20
post-process.ts
packages/next/next-server/lib/post-process.ts
+9
-20
No files found.
packages/next/next-server/lib/post-process.ts
View file @
e6e402e4
import
{
parse
,
HTMLElement
}
from
'node-html-parser'
import
{
parse
,
HTMLElement
}
from
'node-html-parser'
import
{
OPTIMIZED_FONT_PROVIDERS
}
from
'./constants'
import
{
OPTIMIZED_FONT_PROVIDERS
}
from
'./constants'
const
MIDDLEWARE_TIME_BUDGET
=
// const MIDDLEWARE_TIME_BUDGET = parseInt(process.env.__POST_PROCESS_MIDDLEWARE_TIME_BUDGET || '', 10) || 10
parseInt
(
process
.
env
.
__POST_PROCESS_MIDDLEWARE_TIME_BUDGET
||
''
,
10
)
||
10
const
MAXIMUM_IMAGE_PRELOADS
=
2
const
MAXIMUM_IMAGE_PRELOADS
=
2
const
IMAGE_PRELOAD_SIZE_THRESHOLD
=
2500
const
IMAGE_PRELOAD_SIZE_THRESHOLD
=
2500
...
@@ -67,32 +66,22 @@ async function processHTML(
...
@@ -67,32 +66,22 @@ async function processHTML(
const
root
:
HTMLElement
=
parse
(
html
)
const
root
:
HTMLElement
=
parse
(
html
)
let
document
=
html
let
document
=
html
// Calls the middleware, with some instrumentation and logging
// Calls the middleware, with some instrumentation and logging
async
function
callMiddleWare
(
async
function
callMiddleWare
(
middleware
:
PostProcessMiddleware
)
{
middleware
:
PostProcessMiddleware
,
// let timer = Date.now()
name
:
string
)
{
let
timer
=
Date
.
now
()
middleware
.
inspect
(
root
,
postProcessData
,
data
)
middleware
.
inspect
(
root
,
postProcessData
,
data
)
const
inspectTime
=
Date
.
now
()
-
timer
document
=
await
middleware
.
mutate
(
document
,
postProcessData
,
data
)
document
=
await
middleware
.
mutate
(
document
,
postProcessData
,
data
)
timer
=
Date
.
now
()
-
timer
// timer = Date.now() - timer
if
(
timer
>
MIDDLEWARE_TIME_BUDGET
)
{
// if (timer > MIDDLEWARE_TIME_BUDGET) {
console
.
warn
(
// TODO: Identify a correct upper limit for the postprocess step
`The postprocess middleware "
${
name
}
" took
${
timer
}
ms(
${
inspectTime
}
,
${
// and add a warning to disable the optimization
timer
-
inspectTime
// }
}
) to complete. This is longer than the
${
MIDDLEWARE_TIME_BUDGET
}
limit.`
)
}
return
return
}
}
for
(
let
i
=
0
;
i
<
middlewareRegistry
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
middlewareRegistry
.
length
;
i
++
)
{
let
middleware
=
middlewareRegistry
[
i
]
let
middleware
=
middlewareRegistry
[
i
]
if
(
!
middleware
.
condition
||
middleware
.
condition
(
options
))
{
if
(
!
middleware
.
condition
||
middleware
.
condition
(
options
))
{
await
callMiddleWare
(
await
callMiddleWare
(
middlewareRegistry
[
i
].
middleware
)
middlewareRegistry
[
i
].
middleware
,
middlewareRegistry
[
i
].
name
)
}
}
}
}
...
...
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