Next JS 14 – common module styles issue / alternative

I have a Next JS 14 application – utilizing App router. The directory structure is something like the following

some-project/
├── app/
│   ├── layout.js
│   ├── page.js
│   └── ... (other app-related files)
├── components/
│   ├── xyz/
│   │   ├── xyzComponent.tsx
│   │   ├── xyzComponent.module.css
│   │   └── ... (other XYZ-related files)
│   ├── formElements/
│   │   ├── input/
│   │   │   ├── inputComponent.tsx
│   │   │   ├── inputComponent.module.css
│   │   │   └── ... (other input-related files)
│   │   ├── textarea/
│   │   │   ├── textareaComponent.tsx
│   │   │   ├── textareaComponent.module.css
│   │   │   └── ... (other textarea-related files)
│   │   ├── date/
│   │   │   ├── dateComponent.tsx
│   │   │   ├── dateComponent.module.css
│   │   │   └── ... (other date-related files)
│   │   ├── formElements.module.css
│   │   └── ... (other formElements-related files)
├── public/
│   └── ... (public assets like images, fonts, etc.)
├── styles/
│   ├── globals.css
│   └── ... (other global styles)
├── next.config.js
├── package.json
└── ... (other project-related files)

The formElements components share some of the same styles (that I don’t want to repeat, can’t stress that enough) from the formElements.module.css. Here is a sample file

// components/formElements/input/inputComponent.tsx
import React from 'react';
import formStyles from '../formElements.module.css';
import styles from './inputComponent.module.css';

const InputComponent: React.FC = () => {
  return (
    <div className={`${formStyles.container} ${styles.container}`>
      <input className={styles.input} type="text" />
      ...

Now, the page loads perfectly the first time, applying the styles in the order they’re appearing here. When I move away from that page and come back again, Next JS reloads the formStyles once again, but not the styles. As a result, formStyles gets precedence over styles and messes up the style.

Here are my questions

  1. Why might they load formStyles but not styles in the second attempt?
  2. If I should follow a pure module structure and utilize one .module.css per file, what should I do about those common styles from formStyles? I can copy them and paste(/merge) it into all the nested folder’s .module.css file under formElements‘ – but I really don’t want to repeat styles. What would happen if I need to change the common styles later down the road, do I update all the nested files once again?
  3. Any interesting idea for an alternative styling structure?

N.B. I want something other than !important and style property usage suggestions.

What I Did
I tried changing the order of the style imports, appearance in the className – to no avail. I want either for formStyles & styles – both of them to reload in the given order, or not to reload them at all. My ultimate target is to reuse styles and get a consistent appearance.

New contributor

Salman Hossain is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật