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

hds-2183: fix header ssr styles #1250

Merged
merged 6 commits into from
Apr 11, 2024
Merged

Conversation

NikoHelle
Copy link
Contributor

@NikoHelle NikoHelle commented Apr 4, 2024

Description

The order of css classes in SSR (next.js/Gatsby) was different than in "normal" React SPA.

The issue was fixed by re-ordering imports in Header.tsx. The components own style module should be imported before sub components to keep css classes in same order in React and SSR.

Added also an Eslint rule to force ./*.module.scss to be imported before other internal imports. This caused 200+ changes in this PR when Eslint was run with --fix

There was also a weird way to use Header.module.scss in most of the sub components by using @use. This caused Header styles to be duplicated. Removing this resulted in 30kb smaller index.css file.

Built css-files are attached in "css-files.zip". The files are "beautified" with css-beautifier to make comparison easier.

Related Issue

Closes HDS-2183

Motivation and Context

How Has This Been Tested?

  • manually comparing built css files. See "css-files.zip".
  • visual tests still pass
  • error in current docs site is fixed in demo
  • next.js app (v 14.1.4). The app is attached as zip. See README to start it.
  • storybook demo and local versions work

nextjs-hds-example.zip
css-files.zip

Add to changelog

  • [ x] Added needed line to changelog

@NikoHelle NikoHelle requested review from a team April 4, 2024 08:42
Copy link
Contributor

@mrTuomoK mrTuomoK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, thx 👍 just fix the conflict in changelog and it''s good to go.

The order of css rules in production SSR (next.js/Gatsby) seems to be different than in React SPA.

If component styles are imported before subcomponents, the css rule order seem to be consistent.
There are no mixins or scss vars in the header.module.scss, so this @use only adds unused css-classes to built css.
@NikoHelle NikoHelle force-pushed the hds-2183-header-ssr-styles branch from 57205dc to 77f6395 Compare April 11, 2024 07:20
@NikoHelle NikoHelle merged commit dcfee46 into development Apr 11, 2024
6 checks passed
@NikoHelle NikoHelle deleted the hds-2183-header-ssr-styles branch April 11, 2024 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants