-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split lazy and loadable impl, update tests
- Loading branch information
Showing
17 changed files
with
165 additions
and
73 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
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 was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
test/integration/react-18/prerelease/components/dynamic-suspense.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,12 @@ | ||
import { Suspense } from 'react' | ||
import dynamic from 'next/dynamic' | ||
|
||
const Hello = dynamic(() => import('./hello'), { suspense: true }) | ||
|
||
export default function DynamicSuspense({ suspended }) { | ||
return ( | ||
<Suspense fallback={'loading'}> | ||
<Hello suspended={suspended} /> | ||
</Suspense> | ||
) | ||
} |
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 ReactDOM from 'react-dom' | ||
|
||
export default function Hello({ suspended = false }) { | ||
if (suspended && typeof window !== 'undefined') { | ||
throw new Promise((resolve) => setTimeout(resolve, 1000)) | ||
} | ||
return <p>hello {ReactDOM.version}</p> | ||
} |
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
4 changes: 0 additions & 4 deletions
4
test/integration/react-18/prerelease/node_modules/react-dom/package.json
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,22 +1,12 @@ | ||
import dynamic from 'next/dynamic' | ||
import { Suspense } from 'react' | ||
import Bar from './bar' | ||
|
||
const LazyBar = dynamic(() => import('./bar'), { suspense: true }) | ||
import ReactDOM from 'react-dom' | ||
|
||
export default function Index() { | ||
if (typeof window !== 'undefined') { | ||
window.didHydrate = true | ||
} | ||
return ( | ||
<div> | ||
<p>Hello</p> | ||
<Suspense fallback={'loading...'}> | ||
<LazyBar /> | ||
</Suspense> | ||
<Suspense fallback={'loading...'}> | ||
<Bar /> | ||
</Suspense> | ||
<p id="react-dom-version">{ReactDOM.version}</p> | ||
</div> | ||
) | ||
} |
5 changes: 5 additions & 0 deletions
5
test/integration/react-18/prerelease/pages/suspense/content.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,5 @@ | ||
import DynamicSuspense from '../../components/dynamic-suspense' | ||
|
||
export default function Dynamic() { | ||
return <DynamicSuspense suspended={false} /> | ||
} |
5 changes: 5 additions & 0 deletions
5
test/integration/react-18/prerelease/pages/suspense/fallback.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,5 @@ | ||
import DynamicSuspense from '../../components/dynamic-suspense' | ||
|
||
export default function Dynamic() { | ||
return <DynamicSuspense suspended /> | ||
} |
This file was deleted.
Oops, something went wrong.
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,45 @@ | ||
/* eslint-env jest */ | ||
import webdriver from 'next-webdriver' | ||
import cheerio from 'cheerio' | ||
import { check } from 'next-test-utils' | ||
|
||
export default (context, render) => { | ||
async function get$(path, query) { | ||
const html = await render(path, query) | ||
return cheerio.load(html) | ||
} | ||
|
||
describe('suspense:true option', () => { | ||
it('Should render the fallback on the server side', async () => { | ||
const $ = await get$('/suspense/fallback') | ||
const html = $('body').html() | ||
expect(html).toContain('loading') | ||
expect(JSON.parse($('#__NEXT_DATA__').html()).dynamicIds).toContain( | ||
'./components/hello.js' | ||
) | ||
}) | ||
|
||
it('should render the component on client side', async () => { | ||
let browser | ||
try { | ||
browser = await webdriver(context.appPort, '/suspense/fallback') | ||
await check(() => browser.elementByCss('body').text(), /hello/) | ||
} finally { | ||
if (browser) { | ||
await browser.close() | ||
} | ||
} | ||
}) | ||
}) | ||
|
||
describe('suspense:false option', () => { | ||
it('Should render the content on the server side', async () => { | ||
const $ = await get$('/suspense/content') | ||
const html = $('body').html() | ||
expect(html).toContain('hello') | ||
expect(JSON.parse($('#__NEXT_DATA__').html()).dynamicIds).toContain( | ||
'./components/hello.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