Skip to content

Commit

Permalink
Revert "Move in client/index"
Browse files Browse the repository at this point in the history
This reverts commit 592d70c.
  • Loading branch information
timneutkens committed Aug 11, 2022
1 parent 592d70c commit 14b6105
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Expand Up @@ -69,7 +69,7 @@
"warn",
{
"functions": false,
"classes": true,
"classes": false,
"variables": true,
"enums": true,
"typedefs": true
Expand Down
3 changes: 1 addition & 2 deletions packages/next/build/analysis/extract-const-value.ts
Expand Up @@ -15,8 +15,6 @@ import type {
VariableDeclaration,
} from '@swc/core'

export class NoSuchDeclarationError extends Error {}

/**
* Extracts the value of an exported const variable named `exportedName`
* (e.g. "export const config = { runtime: 'experimental-edge' }") from swc's AST.
Expand Down Expand Up @@ -140,6 +138,7 @@ export class UnsupportedValueError extends Error {
this.path = codePath
}
}
export class NoSuchDeclarationError extends Error {}

function extractValue(node: Node, path?: string[]): any {
if (isNullLiteral(node)) {
Expand Down
24 changes: 12 additions & 12 deletions packages/next/client/index.tsx
Expand Up @@ -289,18 +289,6 @@ export async function initialize(opts: { webpackHMR?: any } = {}): Promise<{
return { assetPrefix: prefix }
}

const wrapApp =
(App: AppComponent) =>
(wrappedAppProps: Record<string, any>): JSX.Element => {
const appProps: AppProps = {
...wrappedAppProps,
Component: CachedComponent,
err: initialData.err,
router,
}
return <AppContainer>{renderApp(App, appProps)}</AppContainer>
}

export async function hydrate(opts?: { beforeRender?: () => Promise<void> }) {
let initialErr = initialData.err

Expand Down Expand Up @@ -408,6 +396,18 @@ export async function hydrate(opts?: { beforeRender?: () => Promise<void> }) {
await window.__NEXT_PRELOADREADY(initialData.dynamicIds)
}

const wrapApp =
(App: AppComponent) =>
(wrappedAppProps: Record<string, any>): JSX.Element => {
const appProps: AppProps = {
...wrappedAppProps,
Component: CachedComponent,
err: initialData.err,
router,
}
return <AppContainer>{renderApp(App, appProps)}</AppContainer>
}

router = createRouter(initialData.page, initialData.query, asPath, {
initialProps: initialData.props,
pageLoader,
Expand Down
20 changes: 10 additions & 10 deletions packages/next/lib/is-serializable-props.ts
Expand Up @@ -5,16 +5,6 @@ import {

const regexpPlainIdentifier = /^[A-Za-z_$][A-Za-z0-9_$]*$/

export class SerializableError extends Error {
constructor(page: string, method: string, path: string, message: string) {
super(
path
? `Error serializing \`${path}\` returned from \`${method}\` in "${page}".\nReason: ${message}`
: `Error serializing props returned from \`${method}\` in "${page}".\nReason: ${message}`
)
}
}

export function isSerializableProps(
page: string,
method: string,
Expand Down Expand Up @@ -141,3 +131,13 @@ export function isSerializableProps(

return isSerializable(new Map(), input, '')
}

export class SerializableError extends Error {
constructor(page: string, method: string, path: string, message: string) {
super(
path
? `Error serializing \`${path}\` returned from \`${method}\` in "${page}".\nReason: ${message}`
: `Error serializing props returned from \`${method}\` in "${page}".\nReason: ${message}`
)
}
}
156 changes: 78 additions & 78 deletions packages/next/pages/_document.tsx
Expand Up @@ -346,6 +346,77 @@ function getScripts(
})
}

/**
* `Document` component handles the initial `document` markup and renders only on the server side.
* Commonly used for implementing server side rendering for `css-in-js` libraries.
*/
export default class Document<P = {}> extends Component<DocumentProps & P> {
/**
* `getInitialProps` hook returns the context object with the addition of `renderPage`.
* `renderPage` callback executes `React` rendering logic synchronously to support server-rendering wrappers
*/
static getInitialProps(ctx: DocumentContext): Promise<DocumentInitialProps> {
return ctx.defaultGetInitialProps(ctx)
}

render() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
}

// Add a special property to the built-in `Document` component so later we can
// identify if a user customized `Document` is used or not.
const InternalFunctionDocument: DocumentType =
function InternalFunctionDocument() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
;(Document as any)[NEXT_BUILTIN_DOCUMENT] = InternalFunctionDocument

export function Html(
props: React.DetailedHTMLProps<
React.HtmlHTMLAttributes<HTMLHtmlElement>,
HTMLHtmlElement
>
) {
const {
inAmpMode,
docComponentsRendered,
locale,
scriptLoader,
__NEXT_DATA__,
} = useContext(HtmlContext)

docComponentsRendered.Html = true
handleDocumentScriptLoaderItems(scriptLoader, __NEXT_DATA__, props)

return (
<html
{...props}
lang={props.lang || locale || undefined}
amp={inAmpMode ? '' : undefined}
data-ampdevmode={
inAmpMode && process.env.NODE_ENV !== 'production' ? '' : undefined
}
/>
)
}

function AmpStyles({
styles,
}: {
Expand Down Expand Up @@ -867,6 +938,13 @@ export class Head extends Component<HeadProps> {
}
}

export function Main() {
const { docComponentsRendered } = useContext(HtmlContext)
docComponentsRendered.Main = true
// @ts-ignore
return <next-js-internal-body-render-target />
}

export class NextScript extends Component<OriginProps> {
static contextType = HtmlContext

Expand Down Expand Up @@ -1028,84 +1106,6 @@ export class NextScript extends Component<OriginProps> {
}
}

/**
* `Document` component handles the initial `document` markup and renders only on the server side.
* Commonly used for implementing server side rendering for `css-in-js` libraries.
*/
export default class Document<P = {}> extends Component<DocumentProps & P> {
/**
* `getInitialProps` hook returns the context object with the addition of `renderPage`.
* `renderPage` callback executes `React` rendering logic synchronously to support server-rendering wrappers
*/
static getInitialProps(ctx: DocumentContext): Promise<DocumentInitialProps> {
return ctx.defaultGetInitialProps(ctx)
}

render() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
}

// Add a special property to the built-in `Document` component so later we can
// identify if a user customized `Document` is used or not.
const InternalFunctionDocument: DocumentType =
function InternalFunctionDocument() {
return (
<Html>
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
;(Document as any)[NEXT_BUILTIN_DOCUMENT] = InternalFunctionDocument

export function Html(
props: React.DetailedHTMLProps<
React.HtmlHTMLAttributes<HTMLHtmlElement>,
HTMLHtmlElement
>
) {
const {
inAmpMode,
docComponentsRendered,
locale,
scriptLoader,
__NEXT_DATA__,
} = useContext(HtmlContext)

docComponentsRendered.Html = true
handleDocumentScriptLoaderItems(scriptLoader, __NEXT_DATA__, props)

return (
<html
{...props}
lang={props.lang || locale || undefined}
amp={inAmpMode ? '' : undefined}
data-ampdevmode={
inAmpMode && process.env.NODE_ENV !== 'production' ? '' : undefined
}
/>
)
}

export function Main() {
const { docComponentsRendered } = useContext(HtmlContext)
docComponentsRendered.Main = true
// @ts-ignore
return <next-js-internal-body-render-target />
}

function getAmpPath(ampPath: string, asPath: string): string {
return ampPath || `${asPath}${asPath.includes('?') ? '&' : '?'}amp=1`
}
Expand Down

0 comments on commit 14b6105

Please sign in to comment.