mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Use the realPathname for script tags in document.js
This will help us to fetch these scripts directly from a static server since these paths are resolved.
This commit is contained in:
parent
f602f6dc1e
commit
be2e5a8c23
|
@ -67,10 +67,10 @@ export class Head extends Component {
|
|||
|
||||
render () {
|
||||
const { head, styles, __NEXT_DATA__ } = this.context._documentProps
|
||||
const { pathname, buildId, assetPrefix } = __NEXT_DATA__
|
||||
const { realPathname, buildId, assetPrefix } = __NEXT_DATA__
|
||||
|
||||
return <head>
|
||||
<link rel='preload' href={`${assetPrefix}/_next/${buildId}/page${pathname}`} as='script' />
|
||||
<link rel='preload' href={`${assetPrefix}/_next/${buildId}/page${realPathname}`} as='script' />
|
||||
<link rel='preload' href={`${assetPrefix}/_next/${buildId}/page/_error`} as='script' />
|
||||
{this.getPreloadMainLinks()}
|
||||
{(head || []).map((h, i) => React.cloneElement(h, { key: i }))}
|
||||
|
@ -133,7 +133,7 @@ export class NextScript extends Component {
|
|||
|
||||
render () {
|
||||
const { staticMarkup, __NEXT_DATA__ } = this.context._documentProps
|
||||
const { pathname, buildId, assetPrefix } = __NEXT_DATA__
|
||||
const { realPathname, buildId, assetPrefix } = __NEXT_DATA__
|
||||
|
||||
return <div>
|
||||
{staticMarkup ? null : <script dangerouslySetInnerHTML={{
|
||||
|
@ -147,7 +147,7 @@ export class NextScript extends Component {
|
|||
}
|
||||
`
|
||||
}} />}
|
||||
<script async type='text/javascript' src={`${assetPrefix}/_next/${buildId}/page${pathname}`} />
|
||||
<script async type='text/javascript' src={`${assetPrefix}/_next/${buildId}/page${realPathname}`} />
|
||||
<script async type='text/javascript' src={`${assetPrefix}/_next/${buildId}/page/_error`} />
|
||||
{staticMarkup ? null : this.getScripts()}
|
||||
</div>
|
||||
|
|
|
@ -90,10 +90,18 @@ async function doRender (req, res, pathname, query, {
|
|||
|
||||
if (res.finished) return
|
||||
|
||||
// realPathname is pretty useful in the document.js
|
||||
// In there, we include a proper valid resolved path.
|
||||
// That helps us to server that JSON page directly from a static server.
|
||||
// Basically, this is a requirment for next-export
|
||||
const pageRealPath = await resolvePath(join(dir, 'pages', pathname))
|
||||
const realPathname = pageRealPath.replace(join(dir, 'pages'), '')
|
||||
|
||||
const doc = createElement(Document, {
|
||||
__NEXT_DATA__: {
|
||||
props,
|
||||
pathname,
|
||||
realPathname,
|
||||
query,
|
||||
buildId,
|
||||
buildStats,
|
||||
|
@ -101,6 +109,7 @@ async function doRender (req, res, pathname, query, {
|
|||
err: (err) ? serializeError(dev, err) : null
|
||||
},
|
||||
dev,
|
||||
dir,
|
||||
staticMarkup,
|
||||
...docProps
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue