Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CoCo_Code_Op2
next.js
提交
b2adfde9
N
next.js
项目概览
CoCo_Code_Op2
/
next.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
next.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b2adfde9
编写于
10月 14, 2019
作者:
G
Gerald Monaco
提交者:
Joe Haddad
10月 14, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove _document context (#9068)
上级
09681cd5
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
60 addition
and
58 deletion
+60
-58
packages/next/next-server/lib/document-context.ts
packages/next/next-server/lib/document-context.ts
+9
-0
packages/next/next-server/lib/utils.ts
packages/next/next-server/lib/utils.ts
+7
-1
packages/next/next-server/server/render.tsx
packages/next/next-server/server/render.tsx
+17
-17
packages/next/pages/_document.tsx
packages/next/pages/_document.tsx
+27
-40
未找到文件。
packages/next/next-server/lib/document-context.ts
0 → 100644
浏览文件 @
b2adfde9
import
*
as
React
from
'
react
'
import
{
DocumentProps
}
from
'
./utils
'
type
DocumentContext
=
{
readonly
_documentProps
:
DocumentProps
readonly
_devOnlyInvalidateCacheQueryString
:
string
}
export
const
DocumentContext
=
React
.
createContext
<
DocumentContext
>
(
null
as
any
)
packages/next/next-server/lib/utils.ts
浏览文件 @
b2adfde9
...
...
@@ -4,6 +4,7 @@ import { ComponentType } from 'react'
import
{
ParsedUrlQuery
}
from
'
querystring
'
import
{
ManifestItem
}
from
'
../server/render
'
import
{
NextRouter
}
from
'
./router/router
'
import
{
DocumentContext
as
DocumentComponentContext
}
from
'
./document-context
'
/**
* Types used by both next and next-server
...
...
@@ -20,7 +21,12 @@ export type DocumentType = NextComponentType<
DocumentContext
,
DocumentInitialProps
,
DocumentProps
>
>
&
{
renderDocument
(
Document
:
DocumentType
,
props
:
DocumentProps
):
React
.
ReactElement
}
export
type
AppType
=
NextComponentType
<
AppContextType
,
...
...
packages/next/next-server/server/render.tsx
浏览文件 @
b2adfde9
...
...
@@ -209,8 +209,8 @@ function renderDocument(
'
<!DOCTYPE html>
'
+
renderToStaticMarkup
(
<
AmpStateContext
.
Provider
value
=
{
ampState
}
>
<
Document
__NEXT_DATA__
=
{
{
{
Document
.
renderDocument
(
Document
,
{
__NEXT_DATA__
:
{
dataManager
:
dataManagerData
,
props
,
// The result of getInitialProps
page
:
pathname
,
// The rendered page
...
...
@@ -224,21 +224,21 @@ function renderDocument(
dynamicIds
:
dynamicImportsIds
.
length
===
0
?
undefined
:
dynamicImportsIds
,
err
:
err
?
serializeError
(
dev
,
err
)
:
undefined
,
// Error if one happened, otherwise don't sent in the resulting HTML
}
}
dangerousAsPath
=
{
dangerousAsPath
}
canonicalBase
=
{
canonicalBase
}
ampPath
=
{
ampPath
}
inAmpMode
=
{
inAmpMode
}
isDevelopment
=
{
!!
dev
}
hasCssMode
=
{
hasCssMode
}
hybridAmp
=
{
hybridAmp
}
staticMarkup
=
{
staticMarkup
}
devFiles
=
{
devFiles
}
files
=
{
files
}
dynamicImports
=
{
dynamicImports
}
assetPrefix
=
{
assetPrefix
}
{
...
docProps
}
/>
}
,
dangerousAsPath
,
canonicalBase
,
ampPath
,
inAmpMode
,
isDevelopment
:
!!
dev
,
hasCssMode
,
hybridAmp
,
staticMarkup
,
devFiles
,
files
,
dynamicImports
,
assetPrefix
,
...
docProps
,
})
}
</
AmpStateContext
.
Provider
>
)
)
...
...
packages/next/pages/_document.tsx
浏览文件 @
b2adfde9
...
...
@@ -13,6 +13,7 @@ import {
CLIENT_STATIC_FILES_RUNTIME_AMP
,
CLIENT_STATIC_FILES_RUNTIME_WEBPACK
,
}
from
'
../next-server/lib/constants
'
import
{
DocumentContext
as
DocumentComponentContext
}
from
'
../next-server/lib/document-context
'
export
{
DocumentContext
,
DocumentInitialProps
,
DocumentProps
}
...
...
@@ -21,11 +22,6 @@ export type OriginProps = {
crossOrigin
?:
string
}
export
type
DocumentComponentContext
=
{
readonly
_documentProps
:
DocumentProps
readonly
_devOnlyInvalidateCacheQueryString
:
string
}
export
async
function
middleware
({
req
,
res
}:
DocumentContext
)
{}
function
dedupe
(
bundles
:
any
[]):
any
[]
{
...
...
@@ -52,11 +48,6 @@ function getOptionalModernScriptVariant(path: string) {
* Commonly used for implementing server side rendering for `css-in-js` libraries.
*/
export
default
class
Document
<
P
=
{}
>
extends
Component
<
DocumentProps
&
P
>
{
static
childContextTypes
=
{
_documentProps
:
PropTypes
.
any
,
_devOnlyInvalidateCacheQueryString
:
PropTypes
.
string
,
}
/**
* `getInitialProps` hook returns the context object with the addition of `renderPage`.
* `renderPage` callback executes `React` rendering logic synchronously to support server-rendering wrappers
...
...
@@ -69,17 +60,24 @@ export default class Document<P = {}> extends Component<DocumentProps & P> {
return
{
html
,
head
,
styles
,
dataOnly
}
}
context
!
:
DocumentComponentContext
getChildContext
():
DocumentComponentContext
{
return
{
_documentProps
:
this
.
props
,
// In dev we invalidate the cache by appending a timestamp to the resource URL.
// This is a workaround to fix https://github.com/zeit/next.js/issues/5860
// TODO: remove this workaround when https://bugs.webkit.org/show_bug.cgi?id=187726 is fixed.
_devOnlyInvalidateCacheQueryString
:
process
.
env
.
NODE_ENV
!==
'
production
'
?
'
?ts=
'
+
Date
.
now
()
:
''
,
}
static
renderDocument
<
P
>
(
Document
:
new
()
=>
Document
<
P
>
,
props
:
DocumentProps
&
P
):
React
.
ReactElement
{
return
(
<
DocumentComponentContext
.
Provider
value
=
{
{
_documentProps
:
props
,
// In dev we invalidate the cache by appending a timestamp to the resource URL.
// This is a workaround to fix https://github.com/zeit/next.js/issues/5860
// TODO: remove this workaround when https://bugs.webkit.org/show_bug.cgi?id=187726 is fixed.
_devOnlyInvalidateCacheQueryString
:
process
.
env
.
NODE_ENV
!==
'
production
'
?
'
?ts=
'
+
Date
.
now
()
:
''
,
}
}
>
<
Document
{
...
props
}
/>
</
DocumentComponentContext
.
Provider
>
)
}
render
()
{
...
...
@@ -101,15 +99,13 @@ export class Html extends Component<
HTMLHtmlElement
>
>
{
static
contextTypes
=
{
_documentProps
:
PropTypes
.
any
,
}
static
contextType
=
DocumentComponentContext
static
propTypes
=
{
children
:
PropTypes
.
node
.
isRequired
,
}
context
!
:
DocumentComponentContext
context
!
:
React
.
ContextType
<
typeof
DocumentComponentContext
>
render
()
{
const
{
inAmpMode
}
=
this
.
context
.
_documentProps
...
...
@@ -132,17 +128,14 @@ export class Head extends Component<
HTMLHeadElement
>
>
{
static
contextTypes
=
{
_documentProps
:
PropTypes
.
any
,
_devOnlyInvalidateCacheQueryString
:
PropTypes
.
string
,
}
static
contextType
=
DocumentComponentContext
static
propTypes
=
{
nonce
:
PropTypes
.
string
,
crossOrigin
:
PropTypes
.
string
,
}
context
!
:
DocumentComponentContext
context
!
:
React
.
ContextType
<
typeof
DocumentComponentContext
>
getCssLinks
()
{
const
{
assetPrefix
,
files
}
=
this
.
context
.
_documentProps
...
...
@@ -469,12 +462,9 @@ export class Head extends Component<
}
export
class
Main
extends
Component
{
static
contextTypes
=
{
_documentProps
:
PropTypes
.
any
,
_devOnlyInvalidateCacheQueryString
:
PropTypes
.
string
,
}
static
contextType
=
DocumentComponentContext
context
!
:
DocumentComponentContext
context
!
:
React
.
ContextType
<
typeof
DocumentComponentContext
>
render
()
{
const
{
inAmpMode
,
html
}
=
this
.
context
.
_documentProps
...
...
@@ -484,17 +474,14 @@ export class Main extends Component {
}
export
class
NextScript
extends
Component
<
OriginProps
>
{
static
contextTypes
=
{
_documentProps
:
PropTypes
.
any
,
_devOnlyInvalidateCacheQueryString
:
PropTypes
.
string
,
}
static
contextType
=
DocumentComponentContext
static
propTypes
=
{
nonce
:
PropTypes
.
string
,
crossOrigin
:
PropTypes
.
string
,
}
context
!
:
DocumentComponentContext
context
!
:
React
.
ContextType
<
typeof
DocumentComponentContext
>
// Source: https://gist.github.com/samthor/64b114e4a4f539915a95b91ffd340acc
static
safariNomoduleFix
=
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录