Frontend assets and styles
The frontend asset layer gives the client interface its visual system and its reusable media. It combines shared fonts and page-level styles with component-scoped transitions, then passes those sources through Tailwind, PostCSS, and Sass as part of the client bundle. The wider JavaScript and asset flow is described in JavaScript and asset build pipeline.
Client asset roles
Client-managed images
The client asset tree provides image files for frontend features that need local media. These files are available to the asset build system rather than being part of the style rules themselves.
The current image set includes:
- twitter_64.png for a small social image.
- railsonmaui.png for the Rails on Maui example branding.
References: client/…/twitter_64.png• L1 client/…/railsonmaui.png• L1
Font assets
The interface uses local Open Sans files to keep its main text and headings consistent. The global stylesheet declares the light and bold faces and gives each one a system-font fallback, so text remains usable if a local font cannot load.
The font directory keeps each face in several browser-oriented formats. The stylesheet currently loads the TrueType files for OpenSans-Light and OpenSans-Bold.
References: client/…/application.css• L5-13 client/…/OpenSans-Light.ttf• L1 client/…/OpenSans-Bold.ttf• L1
Stylesheet layers
Global stylesheet
The global stylesheet establishes the visual baseline for the client interface. It loads Tailwind's base, component, and utility layers, sets the page background and body font, and defines shared heading, link, and text-selection behavior.
This baseline enters the client through the Stimulus bundle. Components can then add local layout and state styles without redefining the page-wide rules.
References: client/…/application.css• L1-45 client/…/stimulus-bundle.js• L3-12
Utility styles
Tailwind utility classes provide most component layout and visual treatment at the point where the interface is declared. The content scan covers Rails HTML and templates plus client HTML and JavaScript-like component files, so classes used in either side can contribute to the generated utility set.
The Tailwind theme extends the default sans family with OpenSans-Light. Its typography plugin supports readable rich text areas, such as rendered comment content.
References: tailwind.config.js• L1-18 client/…/CommentBox.jsx• L109-204 client/…/SimpleCommentScreen.jsx• L86-107
Component-scoped styles
CSS Modules isolate styles that belong to one component. React components import the module as a class map, while ReScript components bind to the same kind of generated map. This keeps transition names local and prevents them from becoming global page contracts.
The comment interfaces use these modules for enter and leave opacity transitions. The surrounding layout remains expressed with shared Tailwind utilities, which separates reusable page styling from behavior-specific state styling.
References: config/…/commonWebpackConfig.js• L57-71 client/…/CommentBox.jsx• L98-105 client/…/SimpleCommentScreen.jsx• L76-84 client/…/CommentList.res• L1-10
Sass transition resources
Sass supplies a shared animation value to every SCSS module. The value is also used by the React transition components, so the visual fade and the component lifecycle use the same duration.
The ReScript demo keeps the matching duration in its transition code and stylesheet comments. A change to that timing must preserve the agreement between the CSS fade and the transition timeout.
References: client/…/app-variables.scss• L1-4 client/…/CommentBox.module.scss• L1-18 client/…/SimpleCommentScreen.module.scss• L1-17 client/…/ReScriptShow.module.scss• L1-20 client/…/CommentList.jsx• L52-83
Asset processing chain
Tailwind and PostCSS processing
The style chain treats Tailwind as a source expansion step and PostCSS as the CSS post-processing boundary. Tailwind reads the configured content sources and produces the utility layers used by the client, while Autoprefixer adds browser-specific forms for the supported browser range.
This arrangement lets global CSS use Tailwind directives and @apply while component markup uses utility classes. The browser receives the resulting CSS through the normal client asset bundle.
References: postcss.config.js• L1-6 tailwind.config.js• L5-17 client/…/application.css• L1-3 package.json• L54-80
Sass and CSS Module processing
SCSS files pass through Sass as part of the same asset build. The shared variables file is added to each SCSS module as a resource, and CSS Module output is exposed as a default class map with camel-cased names for existing component imports.
This gives local styles access to shared values without requiring each component to repeat an import. It also keeps the import contract stable for both JavaScript and ReScript consumers.
References: config/…/commonWebpackConfig.js• L26-32 config/…/commonWebpackConfig.js• L57-71 config/…/commonWebpackConfig.js• L75-112 package.json• L98-105
Client style entry
The Stimulus bundle acts as the client-facing style entry. Importing the application stylesheet from that bundle brings the global visual baseline and its font declarations into the browser-facing asset graph.
The component SCSS files join the graph when their owning components import them. This means a component's scoped styles follow the component that needs them instead of forming a second global stylesheet.
The asset movement from source files to generated client packs is part of the parent JavaScript and asset build pipeline.
References: client/…/stimulus-bundle.js• L1-12 client/…/CommentBox.jsx• L10-13 client/…/SimpleCommentScreen.jsx• L16-18 client/…/CommentList.res• L1-3
Change checklist
When these files or sections are changed, remember to consider these:
- When changing application.css, check the client entry that imports it and the Tailwind content paths that determine which classes remain available.
- When changing a font family or face name, update both the
@font-facedeclarations and the Tailwind sans-family extension so utility text and base text keep the same font choice. - When changing a module class name, update every React and ReScript consumer of that class map. CSS Module imports do not expose the old name after the change.
- When changing
$animation-duration, update the matching transition timeout and the separate ReScript timing contract. - When adding a new image or font format, confirm that the asset is referenced through the client asset graph and that its URL is valid in the generated pack.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A Tailwind class is used in a file outside the configured content paths. | The class is absent from the generated CSS and the interface loses that style. | Keep new class-bearing sources under the scanned Rails or client paths, or extend tailwind.config.js. |
| A font family name changes in only one layer. | Base text and Tailwind text can use different fonts or fall back unexpectedly. | Keep application.css @font-face names aligned with the Tailwind fontFamily.sans entry. |
| A CSS Module class is renamed without changing its consumer. | The consumer receives an undefined class and loses the scoped behavior. | Update all imports and class-map lookups for the module. |
| The CSS transition duration differs from the transition timeout. | Elements can appear to finish too early or remain in the transition group too long. | Keep the Sass duration, React timeout, and ReScript timeout synchronized. |
| A local font URL points to a missing asset or unsupported path. | The browser falls back to a system font. | Keep font URLs relative to the stylesheet asset location and retain a usable fallback stack. |
Key files
| File | Why to read it |
|---|---|
| client/…/application.css | Defines the global Tailwind layers, local fonts, page baseline, and shared text rules. |
| client/…/app-variables.scss | Defines the shared Sass value used by component transition styles. |
| client/…/stimulus-bundle.js | Shows the client entry that brings the global stylesheet into the asset graph. |
| tailwind.config.js | Defines the source files scanned for utility classes and the shared sans font extension. |
| postcss.config.js | Defines the Tailwind and Autoprefixer stages for CSS processing. |
| config/…/commonWebpackConfig.js | Shows the shared CSS Module and Sass resource rules used by the frontend bundles. |
| client/…/CommentBox.module.scss | Illustrates a component-scoped transition style that uses the shared Sass value. |
| client/…/ReScriptShow.module.scss | Illustrates the matching scoped style used by the ReScript comment demo. |
| client/…/twitter_64.png | Shows the client-managed image asset set. |
client/app/assets/fonts/OpenSans-Light.ttf | Shows one of the local font files consumed by the global stylesheet. |