Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#36435): apply correct fix #36464

Merged
merged 4 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/next/head.js
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
var head = require('./dist/shared/lib/head')
Object.assign(head.default, head)
module.exports = head.default
module.exports = require('./dist/shared/lib/head')
26 changes: 24 additions & 2 deletions packages/next/taskfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1778,6 +1778,7 @@ export async function compile(task, opts) {
'telemetry',
'trace',
'shared',
'shared_re_exported',
'server_wasm',
// we compile this each time so that fresh runtime data is pulled
// before each publish
Expand Down Expand Up @@ -1916,18 +1917,39 @@ export default async function (task) {
await task.watch('cli/**/*.+(js|ts|tsx)', 'cli', opts)
await task.watch('telemetry/**/*.+(js|ts|tsx)', 'telemetry', opts)
await task.watch('trace/**/*.+(js|ts|tsx)', 'trace', opts)
await task.watch('shared/**/*.+(js|ts|tsx)', 'shared', opts)
await task.watch(
'shared/lib/{amp,config,constants,dynamic,head}.+(js|ts|tsx)',
'shared_re_exported',
opts
)
await task.watch(
'shared/**/!(amp|config|constants|dynamic|head).+(js|ts|tsx)',
'shared',
opts
)
await task.watch('server/**/*.+(wasm)', 'server_wasm', opts)
}

export async function shared(task, opts) {
await task
.source(opts.src || 'shared/**/*.+(js|ts|tsx)')
.source(
opts.src || 'shared/**/!(amp|config|constants|dynamic|head).+(js|ts|tsx)'
)
.swc('server', { dev: opts.dev })
.target('dist/shared')
notify('Compiled shared files')
}

export async function shared_re_exported(task, opts) {
await task
.source(
opts.src || 'shared/**/{amp,config,constants,dynamic,head}.+(js|ts|tsx)'
)
.swc('server', { dev: opts.dev, interopClientDefaultExport: true })
.target('dist/shared')
notify('Compiled shared re-exported files')
}

export async function server_wasm(task, opts) {
await task.source(opts.src || 'server/**/*.+(wasm)').target('dist/server')
notify('Moved server wasm files')
Expand Down
19 changes: 18 additions & 1 deletion test/e2e/type-module-interop/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ describe('Type module interop', () => {
import Link from 'next/link'
import Head from 'next/head'
import Script from 'next/script'
import dynamic from 'next/dynamic'
import { useAmp } from 'next/amp'

export default function Page() {
const Dynamic = dynamic(() => import('../components/example'))

export default function Page() {
const isAmp = useAmp()
return (
<>
<Head>
Expand All @@ -30,6 +35,8 @@ describe('Type module interop', () => {
}}
/>
<p>hello world</p>
<Dynamic />
<p id="isAmp">isAmp: {isAmp ? 'yes' : 'false'}</p>
<Link href="/modules">
<a id="link-to-module">link to module</a>
</Link>
Expand All @@ -52,6 +59,11 @@ describe('Type module interop', () => {
)
}
`,
'components/example.jsx': `
export default function Example() {
return <p>An example components load via next/dynamic</p>
}
`,
},
dependencies: {},
})
Expand All @@ -74,6 +86,11 @@ describe('Type module interop', () => {
it('should render server-side', async () => {
const html = await renderViaHTTP(next.url, '/')
expect(html).toContain('hello world')
// component load via next/dynamic should rendered on the server side
expect(html).toContain('An example components load via next/dynamic')
// imported next/amp should work on the server side
const $ = cheerio.load(html)
expect($('#isAmp').text()).toContain('false')
})

it('should render client-side', async () => {
Expand Down