-
Notifications
You must be signed in to change notification settings - Fork 27.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
560bb26
commit b77f5a6
Showing
14 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
test/production/dynamic-css-client-navigation/dynamic-import/dynamic-import.test.ts
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,35 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
|
||
describe('dynamic-css-client-navigation dynamic import', () => { | ||
const { next, isTurbopack } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
|
||
const isTurbopackBuild = isTurbopack && process.env.TURBOPACK_BUILD | ||
|
||
it('should not remove style when navigating from static imported component to dynamic import', async () => { | ||
const browser = await next.browser('/') | ||
expect( | ||
await browser | ||
.elementByCss('a[href="/dynamic-import"]') | ||
.click() | ||
.waitForElementByCss('#red-button') | ||
.text() | ||
).toBe('Red Button') | ||
|
||
const buttonBgColor = await browser.eval( | ||
`window.getComputedStyle(document.querySelector('button')).backgroundColor` | ||
) | ||
|
||
// TODO: remove this condition after fix | ||
if (isTurbopackBuild) { | ||
expect(buttonBgColor).not.toBe('rgb(239, 239, 239)') | ||
expect(buttonBgColor).toBe('rgb(255, 0, 0)') | ||
} else { | ||
// TODO: replace this after fix | ||
// should be red, but is gray now. | ||
expect(buttonBgColor).toBe('rgb(239, 239, 239)') | ||
expect(buttonBgColor).not.toBe('rgb(255, 0, 0)') | ||
} | ||
}) | ||
}) |
13 changes: 13 additions & 0 deletions
13
...roduction/dynamic-css-client-navigation/dynamic-import/src/components/red-button-lazy.tsx
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 React, { useEffect, useState } from 'react' | ||
|
||
export function RedButtonLazy() { | ||
const [Component, setComponent] = useState<React.ComponentType | null>(null) | ||
|
||
useEffect(() => { | ||
import('./red-button').then((module) => | ||
setComponent(() => module.RedButton) | ||
) | ||
}, []) | ||
|
||
return Component && <Component /> | ||
} |
10 changes: 10 additions & 0 deletions
10
test/production/dynamic-css-client-navigation/dynamic-import/src/components/red-button.tsx
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,10 @@ | ||
import React from 'react' | ||
import classes from './red.module.css' | ||
|
||
export function RedButton() { | ||
return ( | ||
<button id="red-button" className={classes.button}> | ||
Red Button | ||
</button> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
test/production/dynamic-css-client-navigation/dynamic-import/src/components/red.module.css
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,3 @@ | ||
.button { | ||
background-color: rgb(255, 0, 0); | ||
} |
6 changes: 6 additions & 0 deletions
6
test/production/dynamic-css-client-navigation/dynamic-import/src/pages/dynamic-import.tsx
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,6 @@ | ||
import React from 'react' | ||
import { RedButtonLazy } from '../components/red-button-lazy' | ||
|
||
export default function DynamicImport() { | ||
return <RedButtonLazy /> | ||
} |
15 changes: 15 additions & 0 deletions
15
test/production/dynamic-css-client-navigation/dynamic-import/src/pages/index.tsx
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,15 @@ | ||
import React from 'react' | ||
import Link from 'next/link' | ||
import { RedButton } from '../components/red-button' | ||
import { RedButtonLazy } from '../components/red-button-lazy' | ||
|
||
export default function Home() { | ||
return ( | ||
<> | ||
{/* To reproduce, RedButton and RedButtonLazy should be imported. */} | ||
<RedButton /> | ||
<RedButtonLazy /> | ||
<Link href="/dynamic-import">/dynamic-import</Link> | ||
</> | ||
) | ||
} |
61 changes: 61 additions & 0 deletions
61
test/production/dynamic-css-client-navigation/next-dynamic.test.ts
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,61 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
|
||
describe('dynamic-css-client-navigation next/dynamic', () => { | ||
const { next, isTurbopack } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
|
||
const isTurbopackBuild = isTurbopack && process.env.TURBOPACK_BUILD | ||
|
||
it('should not remove style when navigating from static imported component to next/dynamic', async () => { | ||
const browser = await next.browser('/') | ||
expect( | ||
await browser | ||
.elementByCss('a[href="/next-dynamic"]') | ||
.click() | ||
.waitForElementByCss('#red-button') | ||
.text() | ||
).toBe('Red Button') | ||
|
||
const buttonBgColor = await browser.eval( | ||
`window.getComputedStyle(document.querySelector('button')).backgroundColor` | ||
) | ||
|
||
// TODO: remove this condition after fix | ||
if (isTurbopackBuild) { | ||
expect(buttonBgColor).not.toBe('rgb(239, 239, 239)') | ||
expect(buttonBgColor).toBe('rgb(255, 0, 0)') | ||
} else { | ||
// TODO: replace this after fix | ||
// should be red, but is gray now. | ||
expect(buttonBgColor).toBe('rgb(239, 239, 239)') | ||
expect(buttonBgColor).not.toBe('rgb(255, 0, 0)') | ||
} | ||
}) | ||
|
||
it('should not remove style when navigating from static imported component to next/dynamic with ssr: false', async () => { | ||
const browser = await next.browser('/') | ||
expect( | ||
await browser | ||
.elementByCss('a[href="/next-dynamic-ssr-false"]') | ||
.click() | ||
.waitForElementByCss('#red-button') | ||
.text() | ||
).toBe('Red Button') | ||
|
||
const buttonBgColor = await browser.eval( | ||
`window.getComputedStyle(document.querySelector('button')).backgroundColor` | ||
) | ||
|
||
// TODO: remove this condition after fix | ||
if (isTurbopackBuild) { | ||
expect(buttonBgColor).not.toBe('rgb(239, 239, 239)') | ||
expect(buttonBgColor).toBe('rgb(255, 0, 0)') | ||
} else { | ||
// TODO: replace this after fix | ||
// should be red, but is gray now. | ||
expect(buttonBgColor).toBe('rgb(239, 239, 239)') | ||
expect(buttonBgColor).not.toBe('rgb(255, 0, 0)') | ||
} | ||
}) | ||
}) |
26 changes: 26 additions & 0 deletions
26
test/production/dynamic-css-client-navigation/react-lazy.test.ts
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,26 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
|
||
describe('dynamic-css-client-navigation react lazy', () => { | ||
const { next } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
|
||
it('should not remove style when navigating from static imported component to react lazy', async () => { | ||
const browser = await next.browser('/') | ||
expect( | ||
await browser | ||
.elementByCss('a[href="/react-lazy"]') | ||
.click() | ||
.waitForElementByCss('#red-button') | ||
.text() | ||
).toBe('Red Button') | ||
|
||
const buttonBgColor = await browser.eval( | ||
`window.getComputedStyle(document.querySelector('button')).backgroundColor` | ||
) | ||
// TODO: replace this after fix | ||
// should be red, but is gray now. | ||
expect(buttonBgColor).toBe('rgb(239, 239, 239)') | ||
expect(buttonBgColor).not.toBe('rgb(255, 0, 0)') | ||
}) | ||
}) |
10 changes: 10 additions & 0 deletions
10
test/production/dynamic-css-client-navigation/src/components/red-button.tsx
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,10 @@ | ||
import React from 'react' | ||
import classes from './red.module.css' | ||
|
||
export function RedButton() { | ||
return ( | ||
<button id="red-button" className={classes.button}> | ||
Red Button | ||
</button> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
test/production/dynamic-css-client-navigation/src/components/red.module.css
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,3 @@ | ||
.button { | ||
background-color: rgb(255, 0, 0); | ||
} |
15 changes: 15 additions & 0 deletions
15
test/production/dynamic-css-client-navigation/src/pages/index.tsx
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,15 @@ | ||
import React from 'react' | ||
import Link from 'next/link' | ||
import { RedButton } from '../components/red-button' | ||
|
||
export default function Home() { | ||
return ( | ||
<> | ||
{/* To reproduce, RedButton should be imported. */} | ||
<RedButton /> | ||
<Link href="/next-dynamic">/next-dynamic</Link> | ||
<Link href="/next-dynamic-ssr-false">/next-dynamic-ssr-false</Link> | ||
<Link href="/react-lazy">/react-lazy</Link> | ||
</> | ||
) | ||
} |
11 changes: 11 additions & 0 deletions
11
test/production/dynamic-css-client-navigation/src/pages/next-dynamic-ssr-false.tsx
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,11 @@ | ||
import React from 'react' | ||
import dynamic from 'next/dynamic' | ||
|
||
const NextDynamicRedButton = dynamic( | ||
() => import('../components/red-button').then((module) => module.RedButton), | ||
{ ssr: false } | ||
) | ||
|
||
export default function NextDynamic() { | ||
return <NextDynamicRedButton /> | ||
} |
10 changes: 10 additions & 0 deletions
10
test/production/dynamic-css-client-navigation/src/pages/next-dynamic.tsx
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,10 @@ | ||
import React from 'react' | ||
import dynamic from 'next/dynamic' | ||
|
||
const NextDynamicRedButton = dynamic(() => | ||
import('../components/red-button').then((module) => module.RedButton) | ||
) | ||
|
||
export default function NextDynamic() { | ||
return <NextDynamicRedButton /> | ||
} |
15 changes: 15 additions & 0 deletions
15
test/production/dynamic-css-client-navigation/src/pages/react-lazy.tsx
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,15 @@ | ||
import React, { lazy, Suspense } from 'react' | ||
|
||
const ReactLazyRedButton = lazy(() => | ||
import('../components/red-button').then((module) => ({ | ||
default: module.RedButton, | ||
})) | ||
) | ||
|
||
export default function ReactLazy() { | ||
return ( | ||
<Suspense fallback={null}> | ||
<ReactLazyRedButton /> | ||
</Suspense> | ||
) | ||
} |