Skip to content

How to style _layout.tsx? #3828

Description

@maurictg

Hi, I am unable to style a layout.

Environment and reproduction steps:

  • Deno 2.8, Fresh 2.3.3
  • Create a new Deno project, created with deno run -Ar jsr:@fresh/init
  • Make sure you have the following files in the routes folder:

index.tsx

import { define } from "@/utils.ts";
import '@/assets/index.css';
export default define.page(function Home() {
  return (
    <div>Hello world</div>
  );
});

_layout.tsx

import { define } from "@/utils.ts";
import '@/assets/layout.css';
export default define.layout(function Layout({ Component }) {
  return (
    <div>
      <h1 class="layout">Layout</h1>
      <Component />
    </div>
  );
});

assets/layout.css

h1.layout {
    color: red;
}

assets/index.css

h1.test {
    color: green;
}

Result: h1 in index.tsx is colored green, but h1 in layout is not colored red - which is what I should expect.

After running deno task build I have the following files:
_fresh/client/assets/_fresh-route___test-XXXX.css

h1.test{color:green}

_fresh/client/assets/server-entry-XXXX.css

h1.layout{color:red}

So the styles are present. HOWEVER, that server-entry file is never served; so it won't do anything.

Question: is this a bug, should Fresh serve that server-entry.css? Or am I misunderstanding the way of styling?

  • No, I don't want Tailwind CSS.
  • This issue is written by a human
  • Claude and other AIs were unable to solve this problem

Can anyone help? And explain to me what that server-entry CSS file is?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions