form-guard 1.0.1: A Reliability Release
@oblique-code/form-guard helps prevent users from losing unsaved form changes. It protects against accidental navigation, page refreshes, tab closures, back-button navigation, and link clicks.
It's dependency-free, approximately 5 KB gzipped, and includes React and Vue adapters.
Today, we're releasing version 1.0.1 — a bug-fix release focused on reliability, accessibility, browser compatibility, and package quality.
There are no breaking API changes.
If you're using 1.0.0, we recommend upgrading. The first fix alone affects every page using the library.
npm install @oblique-code/form-guard@1.0.1
The important fixes
1. No more false "Leave site?" warnings
In 1.0.0, refreshing or closing a page could trigger the browser's native leave confirmation even when the form hadn't changed.
This is now fixed. The browser warning only appears when there are actual unsaved changes.
2. Client-side routing works correctly
Previously, link clicks could turn into full page reloads, even when the form was clean.
Now, links are only intercepted when the form has unsaved changes. After the user confirms leaving, the original click is replayed.
This allows Next.js <Link>, React Router, and similar client-side routers to handle navigation normally.
3. Special link interactions are preserved
These interactions are no longer intercepted:
- Ctrl/Cmd-click
- Middle-click
- Download links
- In-page
#anchornavigation
4. One confirmation, not two
After a user confirms leaving through the custom modal, the browser's native leave dialog no longer appears as a second confirmation.
Multiple guards on the same page also share a single prompt.
5. The confirmation modal is accessible
One of the most important bugs we found was related to keyboard focus.
The modal appeared visually, but it was still hidden during its fade-in animation. As a result, focusing the "Stay" button failed silently.
Keyboard users could interact with the page behind the modal, and the Tab key could escape the dialog.
This is now fixed.
We also corrected the "Leave" button's color contrast to meet WCAG AA requirements.
6. Invalid form submissions remain protected
With novalidate, submitting a form with an empty required field previously marked it as clean.
That could cause users to lose unsaved changes.
Now, an invalid submission doesn't count as a successful save. The form remains protected until a valid submission.
7. Dynamic forms and native reset
Several additional edge cases are fixed:
-
addForm()no longer discards unsaved changes. -
removeForm()recalculates the dirty state. - Native form reset events are detected.
- Removing the only changed field correctly returns the form to a clean state.
Better package distribution
This release also improves how the package is distributed.
Stylesheet distribution
The compiled stylesheet is now included as dist/styles.css.
Import it using:
import '@oblique-code/form-guard/styles.css';
It is also available through the CDN. The previous /src/styles.css path remains supported for backward compatibility.
TypeScript and CommonJS
CommonJS consumers using require() now receive the correct TypeScript declarations.
We also fixed type resolution for older TypeScript configurations using moduleResolution: node10.
Bundler compatibility
The package now correctly declares CSS as a side effect, preventing bundlers from accidentally removing stylesheet imports.
Content Security Policy
Strict nonce-based Content Security Policy configurations now receive correctly styled confirmation modals.
What changed in the API behaviour?
A few behaviour changes are worth mentioning:
- A guard that has been disabled with
disable()no longer prompts.confirmLeave()returnstruewhile disabled. -
reset()fires thecleancallback only when the form was actually dirty. - Invalid submissions no longer reset the guard's dirty state.
These changes are documented in the changelog.
Testing in real browsers
One of the biggest improvements in this release came from changing how we test the library.
Unit tests running in jsdom were useful, but they couldn't reproduce every real browser behaviour.
We added Playwright end-to-end tests covering:
- Chromium
- Firefox
- WebKit
- Native browser leave dialogs
- Keyboard navigation and focus management
- Single-page application navigation
- Back and forward navigation
- Different HTML form field types
- Multiple guards on the same page
- Strict nonce-based CSP
- Automated accessibility auditing with axe-core
The browser tests uncovered several bugs that the existing unit tests hadn't caught.
We also added package validation using publint, @arethetypeswrong/cli, and a smoke test that installs the packed npm tarball into a separate project.
The result is a more thoroughly tested release, not just a collection of code changes.
What's next?
We're planning several improvements for v1.1:
- Reactive
isDirtysupport for React. - Better integration helpers for Next.js.
- React Router and Vue Router navigation helpers.
- A
getChanges()API to identify which fields have changed.
You can follow the development plan in our roadmap.
Try it out
- npm: https://www.npmjs.com/package/@oblique-code/form-guard
- GitHub: https://github.com/Oblique-Code/form-guard
- Changelog: https://github.com/Oblique-Code/form-guard/blob/main/CHANGELOG.md
- Discussions: https://github.com/Oblique-Code/form-guard/discussions/2
Bug reports, feedback, and contributions are welcome.
If you use the library, we'd appreciate hearing about your experience.
Built and maintained by Oblique Code.
Top comments (0)