Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Jan 10, 2022
1 parent 212e345 commit 645cd45
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/next/build/entries.ts
Expand Up @@ -79,7 +79,7 @@ export function createPagesMapping(
// allow falling back to the correct source file so
// that HMR can work properly when a file is added/removed
const documentPage = `_document${hasConcurrentFeatures ? '-web' : ''}`
const appPage = `_app${hasServerComponents ? '.server' : ''}`
const appPage = `_app${hasServerComponents ? '-server' : ''}`
if (isDev) {
pages['/_app'] = `${PAGES_DIR_ALIAS}/_app`
pages['/_error'] = `${PAGES_DIR_ALIAS}/_error`
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/webpack-config.ts
Expand Up @@ -546,7 +546,7 @@ export default async function getBaseWebpackConfig(
prev.push(path.join(pagesDir, `_app.${ext}`))
return prev
}, [] as string[]),
`next/dist/pages/_app${hasServerComponents ? '.server' : ''}.js`,
`next/dist/pages/_app${hasServerComponents ? '-server' : ''}.js`,
]
customAppAliases[`${PAGES_DIR_ALIAS}/_error`] = [
...config.pageExtensions.reduce((prev, ext) => {
Expand Down
8 changes: 1 addition & 7 deletions packages/next/client/index.tsx
Expand Up @@ -657,12 +657,7 @@ const wrapApp =
err: hydrateErr,
router,
}
return (
<AppContainer>
{renderApp(App, appProps)}
{/* <App {...appProps} /> */}
</AppContainer>
)
return <AppContainer>{renderApp(App, appProps)}</AppContainer>
}

let RSCComponent: (props: any) => JSX.Element
Expand Down Expand Up @@ -977,7 +972,6 @@ function doRender(input: RenderRouteInfo): Promise<any> {
<>
<Head callback={onHeadCommit} />
<AppContainer>
{/* <App {...appProps} /> */}
{renderApp(App, appProps)}
<Portal type="next-route-announcer">
<RouteAnnouncer />
Expand Down
@@ -1,3 +1,5 @@
// Default _app page for server components

import React from 'react'

export default function App({ children }: { children: React.ReactNode }) {
Expand Down
2 changes: 0 additions & 2 deletions packages/next/server/base-server.ts
Expand Up @@ -1220,7 +1220,6 @@ export default abstract class Server {
parsed: parsed,
})
} catch (err) {
console.error('err', err)
if (isError(err) && err.code === 'ENOENT') {
await this.render404(req, res, parsed)
return { finished: true }
Expand Down Expand Up @@ -1404,7 +1403,6 @@ export default abstract class Server {
finished: true,
}
} catch (err) {
console.error('n err', err)
if (err instanceof NoFallbackError && bubbleNoFallback) {
return {
finished: false,
Expand Down
9 changes: 2 additions & 7 deletions packages/next/server/dev/next-dev-server.ts
Expand Up @@ -405,15 +405,11 @@ export default class DevServer extends Server {

process.on('unhandledRejection', (reason) => {
this.logErrorWithOriginalStack(reason, 'unhandledRejection').catch(
(err) => {
console.error(err)
}
() => {}
)
})
process.on('uncaughtException', (err) => {
this.logErrorWithOriginalStack(err, 'uncaughtException').catch((e) => {
console.error(e)
})
this.logErrorWithOriginalStack(err, 'uncaughtException').catch(() => {})
})
}

Expand Down Expand Up @@ -671,7 +667,6 @@ export default class DevServer extends Server {
}
}

console.error(err)
if (!usedOriginalStack) {
if (type === 'warning') {
Log.warn(err + '')
Expand Down
2 changes: 1 addition & 1 deletion packages/next/taskfile.js
Expand Up @@ -1653,7 +1653,7 @@ export async function pages_app(task, opts) {

export async function pages_app_server(task, opts) {
await task
.source('pages/_app.server.tsx')
.source('pages/_app-server.tsx')
.swc('client', { dev: opts.dev })
.target('dist/pages')
}
Expand Down
@@ -0,0 +1,3 @@
export default function Container({ children }) {
return <div className="_app.server">{children}</div>
}
Expand Up @@ -47,6 +47,13 @@ Document.getInitialProps = (ctx) => {
}
`

const rscAppPage = `
import Container from '../components/container.client'
export default function App({children}) {
return <Container>{children}</Container>
}
`

const appWithGlobalCss = `
import '../styles.css'
Expand Down Expand Up @@ -175,6 +182,20 @@ describe('concurrentFeatures - prod', () => {
runBasicTests(context, 'prod')
})

const customAppPageSuite = {
runTests: (context) => {
it('should render app page', async () => {
const html = await renderViaHTTP(context.appPort, '/')
expect(html).toContain('_app.server')
})
},
before: () => appPage.write(rscAppPage),
after: () => appPage.delete(),
}

runSuite('Custom App', 'dev', customAppPageSuite)
runSuite('Custom App', 'prod', customAppPageSuite)

describe('concurrentFeatures - dev', () => {
const context = { appDir }

Expand Down

0 comments on commit 645cd45

Please sign in to comment.