DEV Community

Eyruz Badalzada
Eyruz Badalzada

Posted on

Hygular 1.0 ships with CSS, a DOM runtime, and optional React hooks

I built Hygular for the point where a page goes from static to interactive. A settings screen might start with a few styled buttons. Later it needs a range control, validation, and a form that saves without navigating away. I wanted to keep the HTML I’d already written through all of those changes.

The first stable release, @hygular/core@1.0.0, is on npm. The package includes a stylesheet, a DOM runtime with no third-party JavaScript dependencies, and a separate entry point for React hooks. Here’s what that looks like in a form you could put in an editor.

One form, two submit buttons

Suppose an editor lets you set a volume level, then either save a draft or publish it. Both buttons hit the same endpoint. The server needs the volume and the action the user chose.

<form action="/api/presets" method="post" data-hygular="form" data-ajax="true">
  <label for="volume">Volume</label>
  <div class="group-range" data-hygular="range">
    <input class="form-range" id="volume" name="volume"
           type="range" min="0" max="100" value="20">
  </div>

  <button class="button" type="submit" name="intent" value="draft">
    Save draft
  </button>
  <button class="button is-primary" type="submit" name="intent" value="publish">
    Publish
  </button>
</form>
Enter fullscreen mode Exit fullscreen mode

Install the package with npm install @hygular/core@1.0.0. In the browser entry point, after the markup is available, initialize the runtime once.

import "@hygular/core/css";
import { Hygular } from "@hygular/core";

new Hygular();
Enter fullscreen mode Exit fullscreen mode

Set the slider to 81 and click Save draft. The POST body contains volume=81 and intent=draft as form-data fields. After a successful response, the form resets to its defaults. Move the slider to 81 again and click Publish. The volume is the same, and the server gets intent=publish. Your application owns the endpoint and decides what each action does.

Two of the fixes in 1.0 came out of testing that sequence.

The submit button was disappearing from the request. During beta testing, a native POST carried the selected action, but the AJAX endpoint received neither button’s value. The handler was disabling the clicked button and constructing FormData with just the form. In 1.0 it passes the submitter to FormData and disables the button after collecting the fields. The regression tests cover GET and POST, including a submit button outside the form linked by its form attribute.

The slider could show 81 while the form would submit 20. After a successful save, the native input had reset to 20. The tooltip, fill, and aria-valuetext still said 81. Calling form.reset() directly reproduced it without a network request. The timing matters here. The browser dispatches the reset event before it restores the values. Hygular now reads the inputs on the next task and updates the indicators together. A rejected save leaves the edited value in place.

A React field that outlives its first render

The third fix needed a different setup. I used ChatGPT to suggest cases for the beta review, then checked them in a browser sandbox. One worth keeping was switching projects while leaving the same select mounted.

I rendered project A, switched to B, and picked Editor. The selection looked right on screen. The callback log said ["A", "editor"]. Giving the field a new React key made the problem disappear because it installed a fresh listener.

In 1.0, useSelect keeps the mounted select and calls the latest onChange through a ref. The test checks that the option is still the same DOM node after switching projects, then clicks it and expects ["B", "editor"]. That first assertion matters: remounting the field would otherwise let a broken implementation pass.

Where I’d start

For a static page, import @hygular/core/css and use the utility and component classes directly. For an HTML form like the one above, initialize the runtime in the browser. In a React screen, the hooks are available from @hygular/core/react and can own the lifecycle of individual controls. A plain HTML page can also load the versioned CSS and UMD bundle from a CDN.

One known issue in 1.0.0 concerns Drawer. In WebKit, switching drawers just as the first panel finishes opening can emit hygular.drawer.closed before that panel finishes closing. I’ve reproduced that sequence and am tracking the correction for a patch release.

If you try Hygular on an existing page, the two-button form is a good first check. Point it at an endpoint you control, open the Network tab, and compare the two requests. You can see exactly which parts Hygular handles and which decisions stay in your application.

Documentation · npm package · Source at v1.0.0

Top comments (0)