Skip to content

Commit 84602cd

Browse files
sokratimneutkens
andauthored
make sure children is first in loader tree to fix head css bug on client navigation (#65279)
### What? make sure children is first in loader tree to fix head css bug on client navigation ### Why? ### How? Fixes PACK-3028 --------- Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
1 parent 0edf4f9 commit 84602cd

File tree

13 files changed

+89
-1
lines changed

13 files changed

+89
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/next-swc/crates/napi/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ anyhow = "1.0.66"
6969
backtrace = "0.3"
7070
fxhash = "0.2.1"
7171
dhat = { workspace = true, optional = true }
72+
indexmap = { workspace = true }
7273
napi = { version = "2", default-features = false, features = [
7374
"napi3",
7475
"serde-json",

packages/next-swc/crates/napi/src/app_structure.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{collections::HashMap, path::MAIN_SEPARATOR, sync::Arc};
22

33
use anyhow::{anyhow, Result};
4+
use indexmap::IndexMap;
45
use napi::{
56
bindgen_prelude::External,
67
threadsafe_function::{ErrorStrategy, ThreadsafeFunction, ThreadsafeFunctionCallMode},
@@ -42,7 +43,7 @@ async fn project_fs(project_dir: String, watching: bool) -> Result<Vc<Box<dyn Fi
4243
#[serde(rename_all = "camelCase")]
4344
struct LoaderTreeForJs {
4445
segment: String,
45-
parallel_routes: HashMap<String, ReadRef<LoaderTreeForJs>>,
46+
parallel_routes: IndexMap<String, ReadRef<LoaderTreeForJs>>,
4647
#[turbo_tasks(trace_ignore)]
4748
components: ComponentsForJs,
4849
#[turbo_tasks(trace_ignore)]

packages/next-swc/crates/next-core/src/app_structure.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,14 @@ async fn directory_tree_to_loader_tree(
10181018
);
10191019
}
10201020

1021+
if tree.parallel_routes.len() > 1
1022+
&& tree.parallel_routes.keys().next().map(|s| s.as_str()) != Some("children")
1023+
{
1024+
// children must go first for next.js to work correctly
1025+
tree.parallel_routes
1026+
.move_index(tree.parallel_routes.len() - 1, 0);
1027+
}
1028+
10211029
Ok(Vc::cell(Some(tree.cell())))
10221030
}
10231031

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Page() {
2+
return <main></main>
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Default() {
2+
return null
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#global {
2+
background: rgb(0, 255, 0);
3+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default function Root({
2+
children,
3+
modal,
4+
}: {
5+
children: React.ReactNode
6+
modal: React.ReactNode
7+
}) {
8+
return (
9+
<html>
10+
<body>
11+
{children}
12+
{modal}
13+
</body>
14+
</html>
15+
)
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use client'
2+
3+
import './global.css'
4+
import styles from './styles.module.css'
5+
6+
export default function Page() {
7+
return (
8+
<main>
9+
<p id="global">Hello World</p>
10+
<p id="module" className={styles.module}>
11+
Hello World
12+
</p>
13+
</main>
14+
)
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Link from 'next/link'
2+
3+
export default function Page() {
4+
return (
5+
<main>
6+
<Link href="/">Link</Link>
7+
</main>
8+
)
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.module {
2+
background: rgb(0, 255, 0);
3+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { nextTestSetup } from 'e2e-utils'
2+
3+
describe('css-client-side-nav-parallel-routes', () => {
4+
const { next } = nextTestSetup({
5+
files: __dirname,
6+
})
7+
8+
// Recommended for tests that need a full browser
9+
it('should apply styles after navigation', async () => {
10+
const browser = await next.browser('/source')
11+
await browser.elementByCss('a').click()
12+
expect(
13+
await browser.elementByCss('#global').getComputedCss('background-color')
14+
).toBe('rgb(0, 255, 0)')
15+
expect(
16+
await browser.elementByCss('#module').getComputedCss('background-color')
17+
).toBe('rgb(0, 255, 0)')
18+
})
19+
})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @type {import('next').NextConfig}
3+
*/
4+
const nextConfig = {}
5+
6+
module.exports = nextConfig

0 commit comments

Comments
 (0)