Skip to content

Commit

Permalink
fix: Resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
panteliselef committed Jun 19, 2024
2 parents ebadaa5 + b548fc7 commit 3fd8a99
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ import {
createMetadataComponents,
createMetadataContext,
} from '../../lib/metadata/metadata'
import { RequestAsyncStorageWrapper } from '../async-storage/request-async-storage-wrapper'
import { StaticGenerationAsyncStorageWrapper } from '../async-storage/static-generation-async-storage-wrapper'
import { withRequestStore } from '../async-storage/with-request-store'
import { withStaticGenerationStore } from '../async-storage/with-static-generation-store'
import {
getURLFromRedirectError,
isRedirectError,
Expand All @@ -69,7 +69,6 @@ import {
import { getSegmentParam } from './get-segment-param'
import { getScriptNonceFromHeader } from './get-script-nonce-from-header'
import { parseAndValidateFlightRouterState } from './parse-and-validate-flight-router-state'
import { validateURL } from './validate-url'
import { createFlightRouterStateFromLoaderTree } from './create-flight-router-state-from-loader-tree'
import { handleAction } from './action-handler'
import { isBailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr'
Expand Down Expand Up @@ -115,6 +114,7 @@ import {
import { createServerModuleMap } from './action-utils'
import { isNodeNextRequest } from '../base-http/helpers'
import { parseParameter } from '../../shared/lib/router/utils/route-regex'
import { parseRelativeUrl } from '../../shared/lib/router/utils/parse-relative-url'
import {
getUIErrorHelperName,
getUIErrorStatusCode,
Expand Down Expand Up @@ -324,7 +324,7 @@ async function generateFlight(
},
getDynamicParamFromSegment,
appUsingSizeAdjustment,
staticGenerationStore: { urlPathname },
requestStore: { url },
query,
requestId,
flightRouterState,
Expand All @@ -334,7 +334,7 @@ async function generateFlight(
const [MetadataTree, MetadataOutlet] = createMetadataComponents({
tree: loaderTree,
query,
metadataContext: createMetadataContext(urlPathname, ctx.renderOpts),
metadataContext: createMetadataContext(url.pathname, ctx.renderOpts),
getDynamicParamFromSegment,
appUsingSizeAdjustment,
createDynamicallyTrackedSearchParams,
Expand Down Expand Up @@ -446,7 +446,7 @@ async function ReactServerApp({ tree, ctx, asNotFound }: ReactServerAppProps) {
GlobalError,
createDynamicallyTrackedSearchParams,
},
staticGenerationStore: { urlPathname },
requestStore: { url },
} = ctx
const initialTree = createFlightRouterStateFromLoaderTree(
tree,
Expand All @@ -458,7 +458,7 @@ async function ReactServerApp({ tree, ctx, asNotFound }: ReactServerAppProps) {
tree,
errorType: asNotFound ? 'not-found' : undefined,
query,
metadataContext: createMetadataContext(urlPathname, ctx.renderOpts),
metadataContext: createMetadataContext(url.pathname, ctx.renderOpts),
getDynamicParamFromSegment: getDynamicParamFromSegment,
appUsingSizeAdjustment: appUsingSizeAdjustment,
createDynamicallyTrackedSearchParams,
Expand Down Expand Up @@ -490,7 +490,7 @@ async function ReactServerApp({ tree, ctx, asNotFound }: ReactServerAppProps) {
<AppRouter
buildId={ctx.renderOpts.buildId}
assetPrefix={ctx.assetPrefix}
initialCanonicalUrl={urlPathname}
initialCanonicalUrl={url.pathname + url.search}
// This is the router state tree.
initialTree={initialTree}
// This is the tree of React nodes that are seeded into the cache
Expand Down Expand Up @@ -535,14 +535,14 @@ async function ReactServerError({
GlobalError,
createDynamicallyTrackedSearchParams,
},
staticGenerationStore: { urlPathname },
requestStore: { url },
requestId,
res,
} = ctx

const [MetadataTree] = createMetadataComponents({
tree,
metadataContext: createMetadataContext(urlPathname, ctx.renderOpts),
metadataContext: createMetadataContext(url.pathname, ctx.renderOpts),
errorType,
query,
getDynamicParamFromSegment,
Expand Down Expand Up @@ -584,7 +584,7 @@ async function ReactServerError({
<AppRouter
buildId={ctx.renderOpts.buildId}
assetPrefix={ctx.assetPrefix}
initialCanonicalUrl={urlPathname}
initialCanonicalUrl={url.pathname + url.search}
initialTree={initialTree}
initialHead={head}
initialLayerAssets={null}
Expand Down Expand Up @@ -1029,7 +1029,11 @@ async function renderToHTMLOrFlightImpl(
onHeaders,
maxHeadersLength: 600,
nonce,
bootstrapScripts: [bootstrapScript],
// When debugging the static shell, client-side rendering should be
// disabled to prevent blanking out the page.
bootstrapScripts: renderOpts.isDebugStaticShell
? []
: [bootstrapScript],
formState,
},
})
Expand Down Expand Up @@ -1251,7 +1255,6 @@ async function renderToHTMLOrFlightImpl(
if (uiErrorType) {
res.statusCode = getUIErrorStatusCode(uiErrorType)
}

let hasRedirectError = false
if (isRedirectError(err)) {
hasRedirectError = true
Expand Down Expand Up @@ -1420,7 +1423,7 @@ async function renderToHTMLOrFlightImpl(
])
}

addImplicitTags(staticGenerationStore)
addImplicitTags(staticGenerationStore, requestStore)

if (staticGenerationStore.tags) {
metadata.fetchTags = staticGenerationStore.tags.join(',')
Expand Down Expand Up @@ -1511,17 +1514,20 @@ export const renderToHTMLOrFlight: AppPageRender = (
query,
renderOpts
) => {
// TODO: this includes query string, should it?
const pathname = validateURL(req.url)
if (!req.url) {
throw new Error('Invalid URL')
}

const url = parseRelativeUrl(req.url, undefined, false)

return RequestAsyncStorageWrapper.wrap(
return withRequestStore(
renderOpts.ComponentMod.requestAsyncStorage,
{ req, res, renderOpts },
{ req, url, res, renderOpts },
(requestStore) =>
StaticGenerationAsyncStorageWrapper.wrap(
withStaticGenerationStore(
renderOpts.ComponentMod.staticGenerationAsyncStorage,
{
urlPathname: pathname,
page: renderOpts.routeModule.definition.page,
renderOpts,
requestEndedState: { ended: false },
},
Expand Down

0 comments on commit 3fd8a99

Please sign in to comment.