Unverified Commit 84602cdf authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

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: 's avatarTim Neutkens <tim@timneutkens.nl>
parent 0edf4f95
......@@ -3061,6 +3061,7 @@ dependencies = [
"fxhash",
"getrandom",
"iana-time-zone",
"indexmap 1.9.3",
"lightningcss-napi",
"napi",
"napi-build",
......
......@@ -69,6 +69,7 @@ anyhow = "1.0.66"
backtrace = "0.3"
fxhash = "0.2.1"
dhat = { workspace = true, optional = true }
indexmap = { workspace = true }
napi = { version = "2", default-features = false, features = [
"napi3",
"serde-json",
......
use std::{collections::HashMap, path::MAIN_SEPARATOR, sync::Arc};
use anyhow::{anyhow, Result};
use indexmap::IndexMap;
use napi::{
bindgen_prelude::External,
threadsafe_function::{ErrorStrategy, ThreadsafeFunction, ThreadsafeFunctionCallMode},
......@@ -42,7 +43,7 @@ async fn project_fs(project_dir: String, watching: bool) -> Result<Vc<Box<dyn Fi
#[serde(rename_all = "camelCase")]
struct LoaderTreeForJs {
segment: String,
parallel_routes: HashMap<String, ReadRef<LoaderTreeForJs>>,
parallel_routes: IndexMap<String, ReadRef<LoaderTreeForJs>>,
#[turbo_tasks(trace_ignore)]
components: ComponentsForJs,
#[turbo_tasks(trace_ignore)]
......
......@@ -1018,6 +1018,14 @@ async fn directory_tree_to_loader_tree(
);
}
if tree.parallel_routes.len() > 1
&& tree.parallel_routes.keys().next().map(|s| s.as_str()) != Some("children")
{
// children must go first for next.js to work correctly
tree.parallel_routes
.move_index(tree.parallel_routes.len() - 1, 0);
}
Ok(Vc::cell(Some(tree.cell())))
}
......
export default function Page() {
return <main></main>
}
export default function Root({
children,
modal,
}: {
children: React.ReactNode
modal: React.ReactNode
}) {
return (
<html>
<body>
{children}
{modal}
</body>
</html>
)
}
'use client'
import './global.css'
import styles from './styles.module.css'
export default function Page() {
return (
<main>
<p id="global">Hello World</p>
<p id="module" className={styles.module}>
Hello World
</p>
</main>
)
}
import Link from 'next/link'
export default function Page() {
return (
<main>
<Link href="/">Link</Link>
</main>
)
}
import { nextTestSetup } from 'e2e-utils'
describe('css-client-side-nav-parallel-routes', () => {
const { next } = nextTestSetup({
files: __dirname,
})
// Recommended for tests that need a full browser
it('should apply styles after navigation', async () => {
const browser = await next.browser('/source')
await browser.elementByCss('a').click()
expect(
await browser.elementByCss('#global').getComputedCss('background-color')
).toBe('rgb(0, 255, 0)')
expect(
await browser.elementByCss('#module').getComputedCss('background-color')
).toBe('rgb(0, 255, 0)')
})
})
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}
module.exports = nextConfig
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment