Skip to content

v1.0.1

Latest

Choose a tag to compare

@github-actions github-actions released this 01 Dec 07:49

Bug-fix release. No public API removals.

Fixed

  • beforeunload no longer prompts when the form is clean. Previously every page with a guard showed the browser's "Leave site?" dialog on refresh or close.
  • Clean forms no longer intercept link clicks. When the form is dirty and the user confirms, the click is replayed instead of forcing window.location.href, so SPA routers (Next.js <Link>, React Router, Inertia) keep navigating client-side. The original click is stopped so routers can't navigate while the prompt is open.
  • Ctrl/Cmd/Shift/Alt-click, middle-click, <a download>, target other than _self, # links and in-page anchors on the current URL are no longer intercepted.
  • No second native dialog after the user already confirmed leaving in the modal. The guard stays quiet until the next edit.
  • Back/forward (popstate) does nothing while the form is clean. When dirty it restores the URL where editing happened, and after confirmation goes back one step (was go(-2), which skipped an entry).
  • Several guards on one page share one set of global listeners and show one prompt per navigation. Every dirty guard emits leave.
  • Concurrent confirmLeave() calls share one prompt; the modal never stacks, and body scroll is restored correctly.
  • reset() emits clean only when the form was actually dirty.
  • addForm() keeps unsaved changes in forms that were already guarded (it used to re-snapshot everything).
  • removeForm() recomputes dirty state and disconnects the removed form's MutationObserver and submit listener.
  • Dynamically removed fields leave the snapshot, so deleting the only changed field makes the form clean again.
  • A native form reset (<button type="reset">, form.reset()) now returns the guard to clean.
  • ignoreHiddenFields now also skips fields inside [hidden], display:none or visibility:hidden ancestors.
  • Under a strict CSP, the injected modal <style> reuses the nonce of an existing <script nonce> / <style nonce> on the page.
  • An invalid submit is no longer treated as a save. With novalidate (or JS-handled forms), submit fires even when a required field is empty or a value is invalid. The guard now resets only if every field passes HTML constraint validation, so unsaved data stays protected. Validity is read without firing invalid events.
  • detectContentEditable now matches bare contenteditable and contenteditable="plaintext-only", not only ="true". contenteditable="false" is still skipped.
  • The modal now actually receives keyboard focus. visibility was part of the fade-in, so the dialog was still hidden when it tried to focus "Stay"; browsers refuse to focus hidden elements. Focus stayed behind the modal and the Tab trap didn't work. Found by the Playwright tests.
  • Clicking an in-page #anchor while dirty no longer triggers the prompt (anchors fire popstate, which was treated like the back button).
  • The modal answers as soon as the user clicks; the fade-out no longer delays navigation, and a prompt opened during the fade gets a fresh modal instead of reusing the closing one (a quick second Back press used to slip through).
  • "Leave" button contrast now meets WCAG AA. White on #ef4444 was 3.76:1; the default is now #dc2626 (4.83:1), hover #b91c1c. Found by the axe-core audit.
  • TypeScript types for CommonJS consumers. require() users got ESM-flavoured types ("masquerading as ESM"); there are now .d.cts twins and per-condition types in exports. Subpath types (/react, /vue) also resolve under legacy moduleResolution: node via typesVersions.
  • sideEffects no longer lets bundlers drop CSS imports. It's now ["*.css"] instead of false.
  • src/styles.css now matches the modal. It used different class and variable names (.fg-modal-wrapper, --fg-duration…), so importing it styled nothing. It's now generated from the injected CSS, and a test keeps them in sync.
  • enable() after disable() emits clean if the form was dirty, keeping the Vue isDirty ref in sync.

Changed

  • Stylesheet ships as dist/styles.css, importable as @oblique-code/form-guard/styles.css. The 1.0.0 path @oblique-code/form-guard/src/styles.css keeps working (it now points at the same file).
  • The npm package no longer includes raw src/*.js (source maps still embed the sources). package.json is exported.
  • A disabled guard never prompts: confirmLeave() resolves true while disabled.

Added

  • Real-browser end-to-end tests with Playwright in Chromium, Firefox and WebKit (npm run test:e2e): native beforeunload, modal accessibility and keyboard, links, SPA routing, back/forward, every field type, validation, dark mode, multiple guards and CSP. They run in CI as a job per browser.
  • Automated accessibility audit with axe-core (WCAG 2.0–2.2 A/AA) of the modal in light and dark mode, including hover/focus states, in all three browsers.
  • npm run check:package: publint, arethetypeswrong and an install smoke test of the packed tarball (ESM, CJS, /react, /vue, /styles.css, types). It runs in CI and before npm publish.
  • npm run serve: a dependency-free static server to try the examples at http://localhost:4173/examples/vanilla.html.
  • Test suite (Vitest + jsdom): core, snapshot, events, router, modal, React and Vue adapters, plus the shipped examples (vanilla against the built IIFE bundle). npm test.
  • npm run test:coverage, npm run size (with a 6 KB gzip budget) and npm run release:zip.
  • Versioned release ZIP + SHA-256 checksum (releases/form-guard-vX.Y.Z.zip).
  • GitHub Actions: CI on every push/PR, and a tag-triggered release that attaches the ZIP.
  • Docs: TESTING, RELEASING, ROADMAP.

Docs

  • README: new "React & Vue Adapters: What to Know" section (behaviour, current limitations, exactly what is and isn't tested), stylesheet/CDN usage, TypeScript module-format support, tested browsers.
  • README: measured bundle sizes; corrected React, Vue Router and Next.js Pages Router examples; notes on native reset and CSP.
  • Examples: all three add a required field that starts empty (Company) and validate on save. The vanilla demo adds every other field type (number, date, radio group, range, color, file, multi-select).
  • Examples: React uses onDirty/onClean state (the old isDirty() in render never re-rendered); Vue uses onBeforeRouteLeave instead of a leaking global router.beforeEach; vanilla uses a native "Discard changes" reset and shows an in-page anchor.

Removed

  • .npmignore (redundant — package.json#files already controls what is published).