Brifing

Transitioning from React.js to HTMX: Modern Yet Simple UI Approach for Forum Software

How server-side interactivity is achieved by replacing React.js with HTMX

Hacker News3 min

1The Problems of React.js in Forum Software

Modern frontend libraries like React.js are designed for complex applications but can create unnecessary complexity in projects like forum software where most interactions are localized. In Misago forum software, React.js usage resulted in over 2.3MB of JavaScript files (842KB when gzipped). This increases page load times and creates accessibility issues for users with low bandwidth. Additionally, React.js's compatibility issues with server-side rendering (SSR) and state management complexity unnecessarily prolong development time for projects like forums where most content is static.

2HTMX's Core Working Principle

HTMX, as a library weighing only 14KB, combines traditional server-side rendering approach with modern interactions. Through special attributes (hx-get, hx-post etc.) added to HTML elements, it enables only the relevant HTML fragment to be refreshed from the server upon user interactions. For example, when a forum category is changed, HTMX only updates the div containing the thread list from the server. This approach resembles jQuery's $.get() method but offers completely declarative syntax and doesn't require complex state management like React.js. It integrates perfectly with server-side frameworks like Django.

3Migration Process and Phased Transition Plan

Misago's transition from React.js to HTMX will be implemented through a phased plan extending into 2024. In the first phase, the navbar component will be rewritten with HTMX, followed by core components like thread lists, thread pages, and user profiles. During transition, some pages will remain as 'multi-page applications' (MPA), meaning they'll perform full page reloads. However, critical interactions like liking posts or poll voting will use HTMX or fallback AJAX calls. This strategy enables migration without disrupting user experience.

4Performance Gains and Size Comparison

Removing React.js is expected to significantly reduce Misago's JavaScript payload. Current version (0.39) contains large files like vendor.js (679KB) and misago.js (615KB). With HTMX's 14KB size, total JavaScript size is projected to decrease by over 90%. This will bring noticeable improvement in page load times, better experience for mobile users, and SEO advantages. Additionally, server-side rendering will substantially reduce First Contentful Paint (FCP) time.

5Admin Panel and Django Integration

Misago's admin panel will also transition from React.js to Django views. In the current system, Django's reusable views make adding new admin pages quite easy: just selecting appropriate base view, defining forms, and writing simple templates is sufficient. After HTMX integration, these pages will gain dynamic update capability without SPA (Single Page Application) complexity. Particularly, Django template system's built-in i18n (internationalization) support stands out as another advantage of this approach.

6Developer Experience and Maintenance Ease

Transition to HTMX will also reduce long-term maintenance costs. Problems caused by React.js ecosystem's frequent major version updates and dependency management will disappear. Combining Django's built-in capabilities (form handling, auth, ORM) with HTMX's minimal approach will increase new feature development speed. Especially for plugin developers, APIs will become simpler and more predictable. Moreover, server-side debugging will be much easier than troubleshooting client-side state errors.

7Preserving User Interactions

The HTMX transition is designed to maintain all user experience aspects without degradation. All interactive features like thread following, notifications, and poll voting will continue working the same way. The only difference will be these operations updating only the relevant HTML fragment in the background instead of full page reloads. For example, liking a post will instantly update the post's like counter without affecting the rest of the page (navbar, sidebar etc.). This approach eliminates traditional MPAs' limitations while avoiding SPAs' complexity.

8Future Plans and Bootstrap Integration

After completing HTMX migration, updating Misago's Bootstrap version is also planned. New components and CSS features in recent Bootstrap versions will help maintain the forum's modern appearance. These two changes (HTMX and Bootstrap update) will make Misago both lighter and more modern. Additionally, it's emphasized that these changes will preserve Misago's modular structure, continuing to offer flexibility to third-party theme and plugin developers. The project maintainer states this transition will make Misago 'a software that can still be run 20 years later'.

Original article: Hacker News — React.js'den HTMX'e Geçiş: Forum Yazılımında Modern ve Basit UI Yaklaşımı