From 6edc1a73c39e4e1dd4df5f3ea9cbc7586d468c28 Mon Sep 17 00:00:00 2001
From: Gerald Monaco
Date: Fri, 18 Feb 2022 03:10:04 +0000
Subject: [PATCH] Remove useMaybeDeferContent hook
---
packages/next/pages/_document.tsx | 391 ++++++++++------------
packages/next/server/render.tsx | 8 -
packages/next/shared/lib/html-context.ts | 3 +-
packages/next/shared/lib/utils.ts | 5 -
test/unit/use-maybe-defer-content.test.ts | 12 -
5 files changed, 171 insertions(+), 248 deletions(-)
delete mode 100644 test/unit/use-maybe-defer-content.test.ts
diff --git a/packages/next/pages/_document.tsx b/packages/next/pages/_document.tsx
index 6af1f81fc86a..309ae6321dcb 100644
--- a/packages/next/pages/_document.tsx
+++ b/packages/next/pages/_document.tsx
@@ -492,7 +492,6 @@ export class Head extends Component<
unstable_runtimeJS,
unstable_JsPreload,
disableOptimizedLoading,
- useMaybeDeferContent,
optimizeCss,
optimizeFonts,
runtime,
@@ -610,36 +609,96 @@ export class Head extends Component<
inAmpMode
)
- // Must use nested component to allow use of a custom hook
- const DeferrableHead = () => {
- const getDynamicHeadContent = () => {
- return (
+ return (
+
+ {!hasConcurrentFeatures && this.context.isDevelopment && (
<>
- {head}
-
+
>
- )
- }
+ )}
+ {head}
+
+
+ {children}
+ {optimizeFonts && }
- const getDynamicScriptPreloads = () => {
- return (
+ {inAmpMode && (
<>
+
+ {!hasCanonicalRel && (
+
+ )}
+ {/* https://www.ampproject.org/docs/fundamentals/optimize_amp#optimize-the-amp-runtime-loading */}
+
+
+
+
+
+ >
+ )}
+ {!inAmpMode && (
+ <>
+ {!hasAmphtmlRel && hybridAmp && (
+
+ )}
+ {!optimizeCss && this.getCssLinks(files)}
+ {!optimizeCss && }
+
{!disableRuntimeJS &&
!disableJsPreload &&
this.getPreloadDynamicChunks()}
{!disableRuntimeJS &&
!disableJsPreload &&
this.getPreloadMainLinks(files)}
- >
- )
- }
- const getDynamicScriptContent = () => {
- return (
- <>
+ {!disableOptimizedLoading &&
+ !disableRuntimeJS &&
+ this.getPolyfillScripts()}
+
{!disableOptimizedLoading &&
!disableRuntimeJS &&
this.getPreNextScripts()}
@@ -649,120 +708,21 @@ export class Head extends Component<
{!disableOptimizedLoading &&
!disableRuntimeJS &&
this.getScripts(files)}
- >
- )
- }
- const [isDeferred] = useMaybeDeferContent('HEAD', () => {
- return (
- <>
- {getDynamicHeadContent()}
- {getDynamicScriptPreloads()}
- {getDynamicScriptContent()}
+ {optimizeCss && this.getCssLinks(files)}
+ {optimizeCss && }
+ {this.context.isDevelopment && (
+ // this element is used to mount development styles so the
+ // ordering matches production
+ // (by default, style-loader injects at the bottom of )
+
+ )}
+ {styles || null}
>
- )
- })
-
- return (
-
- {!hasConcurrentFeatures && this.context.isDevelopment && (
- <>
-
-
- >
- )}
- {!isDeferred && getDynamicHeadContent()}
-
- {children}
- {optimizeFonts && }
-
- {inAmpMode && (
- <>
-
- {!hasCanonicalRel && (
-
- )}
- {/* https://www.ampproject.org/docs/fundamentals/optimize_amp#optimize-the-amp-runtime-loading */}
-
-
-
-
-
- >
- )}
- {!inAmpMode && (
- <>
- {!hasAmphtmlRel && hybridAmp && (
-
- )}
- {!optimizeCss && this.getCssLinks(files)}
- {!optimizeCss && }
-
- {!isDeferred && getDynamicScriptPreloads()}
-
- {!disableOptimizedLoading &&
- !disableRuntimeJS &&
- this.getPolyfillScripts()}
-
- {!isDeferred && getDynamicScriptContent()}
-
- {optimizeCss && this.getCssLinks(files)}
- {optimizeCss && }
- {this.context.isDevelopment && (
- // this element is used to mount development styles so the
- // ordering matches production
- // (by default, style-loader injects at the bottom of