-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Alias nextjs api entry to esm version for app router
- Loading branch information
Showing
17 changed files
with
176 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use client' | ||
|
||
import { useRouter } from 'next/navigation.js' | ||
|
||
export function ClientHooks() { | ||
useRouter() | ||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use client' | ||
|
||
import { useRouter } from 'next/navigation' | ||
|
||
export function ClientHooks() { | ||
useRouter() | ||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import NextImage, { unstable_getImgProps } from 'next/image.js' | ||
import Link from 'next/link.js' | ||
import Script from 'next/script.js' | ||
|
||
import src from '../../public/test.jpg' | ||
|
||
export function Components() { | ||
return ( | ||
<> | ||
<NextImage className="img" src={src} /> | ||
<p className="unstable_getImgProps">{typeof unstable_getImgProps}</p> | ||
<Link className="link" href="/client"> | ||
link | ||
</Link> | ||
<Script className="script" src="/test-ext.js" /> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import NextImage, { unstable_getImgProps } from 'next/image' | ||
import Link from 'next/link' | ||
import Script from 'next/script' | ||
|
||
import src from '../../public/test.jpg' | ||
|
||
export function Components() { | ||
return ( | ||
<> | ||
<NextImage className="img" src={src} /> | ||
<p className="unstable_getImgProps">{typeof unstable_getImgProps}</p> | ||
<Link className="link" href="/client"> | ||
link | ||
</Link> | ||
<Script className="script" src="/test.js" /> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ClientHooks } from './client-hooks-ext' | ||
import { headers, cookies } from 'next/headers.js' | ||
|
||
export function useHooks() { | ||
headers() | ||
cookies() | ||
return <ClientHooks /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ClientHooks } from './client-hooks' | ||
import { headers, cookies } from 'next/headers' | ||
|
||
export function useHooks() { | ||
headers() | ||
cookies() | ||
return <ClientHooks /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useHooks } from './hooks' | ||
import { useHooks as useHooks2 } from './hooks-ext' | ||
import { Components } from './components' | ||
import { Components as Components2 } from './components-ext' | ||
|
||
export default function Page() { | ||
useHooks() | ||
useHooks2() | ||
|
||
return ( | ||
<> | ||
<div id="without-ext"> | ||
<Components /> | ||
</div> | ||
<div id="with-ext"> | ||
<Components2 /> | ||
</div> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const metadata = { | ||
title: 'Next.js', | ||
description: 'Generated by Next.js', | ||
} | ||
|
||
export default function RootLayout({ children }) { | ||
return ( | ||
<html lang="en"> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { createNextDescribe } from 'e2e-utils' | ||
|
||
createNextDescribe( | ||
'app-dir - esm js extension', | ||
{ | ||
files: __dirname, | ||
}, | ||
({ next }) => { | ||
it('should be able to render nextjs api in app router', async () => { | ||
const $ = await next.render$('/app') | ||
|
||
async function validateDomNodes(selector: string) { | ||
expect(await $(`${selector} .img`).prop('tagName')).toBe('IMG') | ||
expect(await $(`${selector} .link`).prop('tagName')).toBe('A') | ||
expect(await $(`${selector} .unstable_getImgProps`).text()).toContain( | ||
'function' | ||
) | ||
} | ||
|
||
await validateDomNodes('#with-ext') | ||
await validateDomNodes('#without-ext') | ||
|
||
expect($('head link[href="/test-ext.js"]').length).toBe(1) | ||
expect($('head link[href="/test.js"]').length).toBe(1) | ||
}) | ||
|
||
it('should be able to use nextjs api in pages router', async () => { | ||
const $ = await next.render$('/pages') | ||
|
||
expect(await $('meta[name="head-value-1"]').attr('content')).toBe( | ||
'with-ext' | ||
) | ||
expect(await $('meta[name="head-value-2"]').attr('content')).toBe( | ||
'without-ext' | ||
) | ||
expect(await $('.root').text()).toContain('pages') | ||
}) | ||
} | ||
) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from 'next/app.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Html, Head, Main, NextScript } from 'next/document.js' | ||
|
||
export default function MyDocument() { | ||
return ( | ||
<Html> | ||
<Head /> | ||
<body> | ||
<Main /> | ||
<NextScript /> | ||
</body> | ||
</Html> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Head from 'next/head' | ||
import AnotherHead from 'next/head.js' | ||
import { useRouter } from 'next/router' | ||
import { useRouter as useRouter2 } from 'next/router.js' | ||
|
||
export default function Page() { | ||
useRouter() | ||
useRouter2() | ||
return ( | ||
<> | ||
<Head> | ||
<meta name="head-value-1" content="with-ext" /> | ||
</Head> | ||
<AnotherHead> | ||
<meta name="head-value-2" content="without-ext" /> | ||
</AnotherHead> | ||
<div className="root">pages</div> | ||
</> | ||
) | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.