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

Test that cross-page styles do not apply #16129

Draft
wants to merge 5 commits into
base: canary
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"browserslist": "^4.14.7",
"browserstack-local": "1.4.0",
"cheerio": "0.22.0",
"classnames": "2.2.6",
"clone": "2.1.2",
"cookie": "0.4.1",
"cors": "2.8.5",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react'
import Link from 'next/link'
import cx from 'classnames'
import styles from './Banner.module.css'

const Banner = ({ id, className, href }) => {
return (
<div id={`hero-${id}`} className={cx(styles.Banner, className)}>
<h1 style={{ margin: 0, padding: '2rem' }}>This is a test</h1>

<Link href={href}>
<a id={`link-${id}`} style={{ margin: 0, padding: '2rem' }}>
Other Page
</a>
</Link>
</div>
)
}

export default Banner
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.Banner {
height: 100vh;
width: 100vw;
background-color: #639;
}
8 changes: 8 additions & 0 deletions test/integration/css-fixtures/next-issue-15284/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// global CSS
import './styles/globalStyles.css'

function App({ Component, pageProps }) {
return <Component {...pageProps} />
}

export default App
6 changes: 6 additions & 0 deletions test/integration/css-fixtures/next-issue-15284/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import styles from './styles/index.module.css'
import Banner from '../components/Banner/Banner'

export default function Index() {
return <Banner id="home" className={styles.bannerOverride} href="/test" />
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
body {
margin: 0;
}

* {
box-sizing: border-box;
color: white;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.bannerOverride {
height: 50vh;
border: 1px solid red;
background-color: #ff6347;
}
5 changes: 5 additions & 0 deletions test/integration/css-fixtures/next-issue-15284/pages/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Banner from '../components/Banner/Banner'

export default function Test() {
return <Banner id="other" href="/" />
}
93 changes: 93 additions & 0 deletions test/integration/css/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1826,4 +1826,97 @@ describe('CSS Support', () => {
}
})
})

// https://github.com/vercel/next.js/issues/15284
describe('CSS Page Ordering', () => {
const appDir = join(fixturesDir, 'next-issue-15284')
let app, appPort

function tests() {
async function checkTomatoBackground(browser) {
await browser.waitForElementByCss('#hero-home')
const titleColor = await browser.eval(
`window.getComputedStyle(document.querySelector('#hero-home')).backgroundColor`
)
expect(titleColor).toBe('rgb(255, 99, 71)')
}
async function checkRebeccaPurpleBackground(browser) {
await browser.waitForElementByCss('#hero-other')
const titleColor = await browser.eval(
`window.getComputedStyle(document.querySelector('#hero-other')).backgroundColor`
)
expect(titleColor).toBe('rgb(102, 51, 153)')
}

it('should have correct color on index page (on load)', async () => {
const browser = await webdriver(appPort, '/')
try {
await checkTomatoBackground(browser)
} finally {
await browser.close()
}
})

it('should have correct color on index page (on hover)', async () => {
const browser = await webdriver(appPort, '/')
try {
await checkTomatoBackground(browser)
await browser.waitForElementByCss('#link-home').moveTo()
await waitFor(2000)
await checkTomatoBackground(browser)
} finally {
await browser.close()
}
})

it('should have correct color on index page (on nav)', async () => {
const browser = await webdriver(appPort, '/')
try {
await checkTomatoBackground(browser)
await browser.waitForElementByCss('#link-home').click()

// Wait for navigation:
await browser.waitForElementByCss('#link-other')
await checkRebeccaPurpleBackground(browser)

// Navigate back to index:
await browser.waitForElementByCss('#link-other').click()
await checkTomatoBackground(browser)
} finally {
await browser.close()
}
})
}

describe('Development Mode', () => {
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})

tests()
})

describe('Production Mode', () => {
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
beforeAll(async () => {
await nextBuild(appDir, [], {})
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})

tests()
})
})
})
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4756,6 +4756,7 @@ class-utils@^0.3.5:
[email protected]:
version "2.2.6"
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.2.6.tgz#43935bffdd291f326dad0a205309b38d00f650ce"
integrity sha512-JR/iSQOSt+LQIWwrwEzJ9uk0xfN3mTVYMwt1Ir5mUcSN6pU+V4zQFFaJsclJbPuAUQH+yfWef6tm7l1quW3C8Q==

clean-stack@^2.0.0:
version "2.2.0"
Expand Down