Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

sass imported styles are null on server, but correct on client #159

@SimonErich

Description

@SimonErich

Hi,

we are thinking about using your package in one of our projects and we usually really like to use sass with css-modules on every component for styling.
We tried to implement it the way, we always do, but there seems to be a problem with the serverside rendering part.

We import the styles with

import * as styles from './STYLEFILE.scss

Then we want to access the different style Classnames like

<div className={styles.ClassName} />

The problem now is, that we end up getting undefined as the className, but if we change something and use hotreload (so it rerenders on the client side only), it works and shows the className correctly.
Also console.logging the className gives the correct result.

Here is our example DemoComponent:

import * as React from "react";
import { GetHackerNewsTopStoriesQuery } from "@/graphql";
import * as styles from './DemoListing.scss';

interface IDemoListingPropType {
  data?: GetHackerNewsTopStoriesQuery,
}

export class DemoListing extends React.PureComponent<IDemoListingPropType> {
  public render() {
    const { data } = this.props;
    
    console.log('Check it here: ', styles.List);

    return (
      <ul className={styles.List}>
        {data!.hn!.topStories!.map(story => (
          <li key={story!.id!}>
            <a href={story!.url!} target="_blank">
              {story!.title}
            </a>
          </li>
        ))}
      </ul>
    );
  }
}

And here is our DemoListing.scss file:

.List {
  list-style-type:none;
  margin:0;
  padding:0;

  li {
    display:block;
    border-bottom:1px solid #e7e7e7;
    padding:10px 0;
    font-size:12px;
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions