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

CSS Modules from default.tsx page are not loading on a parallel route hard navigation #52245

Closed
1 task done
tjabbe opened this issue Jul 5, 2023 · 12 comments · Fixed by #61428
Closed
1 task done

CSS Modules from default.tsx page are not loading on a parallel route hard navigation #52245

tjabbe opened this issue Jul 5, 2023 · 12 comments · Fixed by #61428
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked

Comments

@tjabbe
Copy link
Contributor

tjabbe commented Jul 5, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:22 PDT 2023; root:xnu-8796.121.3~7/RELEASE_X86_64
    Binaries:
      Node: 18.16.0
      npm: 9.5.1
      Yarn: 1.22.19
      pnpm: N/A
    Relevant Packages:
      next: 13.4.18-canary.0
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 4.9.5
    Next.js Config:
      output: N/A

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true)

Link to the code that reproduces this issue or a replay of the bug

https://github.com/tjabbe/css-modules-parallel-routes-default-page

https://codesandbox.io/p/github/tjabbe/css-modules-parallel-routes-default-page/main

To Reproduce

  • Navigate to http://localhost:3000
  • Click on Go to /demo parallel route link --> headline should still have its css module styling
  • Hard refresh when on the /demo route --> headline lost its styling from the CSS Module class (global styles work fine)

Describe the Bug

Hard navigating to a parallel route prevents CSS Modules styles inside app/default.tsx page from being injected.

As you can see on the screenshot, after a hard navigation to /demo, the class gets applied to the <Headline> component, but no css is loaded (except for the global css loaded in the layout)
cssmodules

I could pin down which PR caused this to stop working, it got released in v13.4.6-canary.5: #51018

Expected Behavior

CSS Modules from app/default.tsx page should load when hard navigating to a parallel route.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

NEXT-2310

@tjabbe tjabbe added the bug Issue was opened via the bug report template. label Jul 5, 2023
@github-actions github-actions bot added the area: app App directory (appDir: true) label Jul 5, 2023
@Terro216
Copy link
Contributor

Terro216 commented Jul 9, 2023

Ran into the same bug

@jthorupp
Copy link

jthorupp commented Jul 11, 2023

I might have stumbled into the same issue. Styles from CSS Modules are not added to HTML server-side so a flash of unstyled content happens after (what i believe is) rehydration. Not using app folder in my setup but otherwise more or less identical regarding how styles are imported and used in a component.

This only happens in development. When building the app for production the styles are included in the SSR.

@VladMarkus
Copy link

Any updates?

@mjad218
Copy link

mjad218 commented Jul 17, 2023

I am facing the same issue!

I have a production app that has this bug:

When you go to https://staging.qawalleb.com every thing works as expected.

After navigating to https://staging.qawalleb.com/new through the menu

The styles are not getting loaded.

Please login first to see the issue as /new is a protected route. (It's a staging env, so no data is kept)

@mjad218
Copy link

mjad218 commented Jul 17, 2023

Same issue here #49871
Next @13.4.9

@takefumi-yoshii
Copy link

I got into the same bug.

@tinleym
Copy link

tinleym commented Sep 11, 2023

@shuding I'm sure you're very busy, but is this issue on anyone's radar? I can confirm that this behavior persists in 13.4.19.

@juanpin-humane

This comment has been minimized.

@cberry-humane
Copy link

I believe this is related:

The issue I am seeing is client side navigating, using <Link href="/photo/[id]"/> to the route described below does not load css from the include2 parallel route; that css is imported from the component level not the page level as in include1

I tried moving the css from the components to include2 but didn't work.

The only thing that did work is removing the loading.js file from include2 for whatever reason.

app
  (folder)
    (folder)
      photo
        [id]
          @include1
            loading.js
            page.module.css
            page.tsx
          @include2 <-- no css loaded on this parallel route when client side navigation to this page (/photo/[id])
            loading.js
            page.tsx <-- which includes components which include their own module.css
          error.tsx
          page.tsx
          loading.tsx        

@FredTreg
Copy link

Same issue in 14.0.4. I had to move all my css up to the layout to get this to work

@luanmm
Copy link

luanmm commented Dec 31, 2023

I'm working on a project that uses CSS Modules, so all styles are scoped (can't put the styles in the layout or anything like that). I just can't get it working on default.tsx files.

Another thing regarding default.tsx files: why is this required in the first place?

I'm using a structure like below:

route1
     @parallel
         [param]
              page.tsx
         default.tsx
     default.tsx <-- this renders with problems (when the page is accessed directly only)
     layout.tsx
     page.tsx
     styles.module.scss

And my default.tsx files are nothing more than this:

import Page from './page'

export default Page

This is why I need the page rendering exactly as always (accessed directly or not). So it seems a "dummy" or "filler" file to me. Really don't know why the behavior couldn't be the same as page.tsx if there is no default.tsx page (but ok, this seems another topic).

Any thoughts regarding the styling problems? It seems tightly related to this issue.

@ztanner ztanner added the linear: next Confirmed issue that is tracked by the Next.js team. label Jan 31, 2024
ztanner added a commit that referenced this issue Jan 31, 2024
### What
When using a default slot that re-exports another page, the CSS entries
(and presumably other client reference modules, like JS entries) that
correspond with the re-exported page won't be loaded, resulting in CSS
styles not being applied.

### Why
`next-app-loader` constructs the path to the default segment but special
cases the `children` slot (which is used as the page), to mark the
segment as an empty string. This is so that the parallel default file
can be loaded. However the way that `defaultPath` is constructed, it
assumes that `actualSegment` won't be an empty string, and constructs an
invalid path like so:

`app/example//default.tsx`

When we go to look up the JS/CSS entries from the client reference
manifest, the key will be incorrect and so it won't find the files for
it, resulting in this bug.

### How
This moves the `/` delimiting to be part of the creation of the
`actualSegment` variable so that we only append it when we know we
aren't setting it to be an empty string.

Fixes #52245
Fixes #49871
Closes NEXT-2309
Closes NEXT-2310
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked
Projects
None yet
Development

Successfully merging a pull request may close this issue.