Skip to content

Ajv as peer dependency #1557

Open
Open

Description

@sdirix

At the moment we're bundling Ajv with JSON Forms. While validation is a core concern of JSON Forms we are forcing our users to use our bundled Ajv or to include it twice. Therefore we should transform Ajv to a peer dependency and maybe make it optional in general.

Activity

  1. added this to the 3.x milestone on Mar 10, 2020
  2. modified the milestones: 3.x, 3.0, Backlog on May 10, 2021
  3. modified the milestones: Backlog, next, 3.x on Nov 8, 2022
  4. modified the milestones: 3.x, 4.x on Jul 5, 2024
  5. modified the milestones: 4.x, 4.0 on Aug 14, 2024
  6. andrewperry commented on Oct 22, 2026

    @andrewperry

    We'd like to help with this, scoped so that it doesn't break adopters and can land in 3.x.

    Our use case: we use @jsonforms/core directly, with our own Lit (web components) binding and renderers, under a strict CSP (no 'unsafe-eval') on websites and in Capacitor apps. In our tests with the Form Validator from #2644, we validate with an interpreter (@cfworker/json-schema) and never use Ajv. Even so, Ajv and ajv-formats are about 40 kB gzip of our form bundle (136.0 kB → 96.4 kB without them), because core imports them statically for its fallback createAjv(). #2648 deliberately keeps that import.

    Proposal: an opt-in entry point, @jsonforms/core/core-only, for 3.x

    • @jsonforms/core is unchanged: same exports, Ajv still the default. Nothing changes for the bindings or renderer sets.
    • @jsonforms/core/core-only exports everything except createAjv, createAjvValidator and validate, and never loads Ajv. Validation needs a validator, an ajv instance, or validationMode: 'NoValidation'. Otherwise init throws an error explaining that.
    • How: Ajv moves into one module (util/validator.ts), which registers itself as the default when loaded. The reducer asks for the default instead of importing createAjv. Rollup builds both entry points with a shared chunk, so importing both doesn't duplicate core. There's no exports map, so deep imports keep working; the subpath resolves through a small core-only/package.json.

    It's stacked on #2644 (and #2645/#2648), since without a Form Validator an Ajv-free core could only turn validation off. Making Ajv an optional peer dependency, as this issue originally proposed, would still be a natural 4.0 follow-up, and this entry point would make that step smaller.

    We have a working branch with tests and can open a draft PR on top of #2644 if this direction suits you. Open questions:

    1. The name: we went with core-only (core without a bundled validator). Happy to change it if you prefer another.
    2. Throwing when no validator is configured, versus silently skipping validation. We chose to throw so that forms relying on required checks can't lose them unnoticed.

    Branch: collaboratory-int/jsonforms@master...feat/core-only-entry (the last three commits are ours; the rest is the #2644 stack). Our commits alone: collaboratory-int/jsonforms@1cbe9bd...feat/core-only-entry

  7. sdirix commented on Oct 22, 2026

    @sdirix
    MemberAuthor

    Hi @andrewperry,

    Generally speaking this sounds like a solid plan. Do you have specific urgency on this? If the AJV paths are actually unused today in your applications, you can also workaround the issue by bundling-magic, replacing ajv and ajv-formats with empty stubs.

  8. andrewperry commented on Oct 26, 2026

    @andrewperry

    Thanks, our form builder component that depends on it is currently carrying the extra payload, rather than use the fork that we shared with the commits that implement the update on top of the other contributions made by @gigibiffi84 that support it: collaboratory-int/jsonforms@master...feat/core-only-entry

    Given the work contributed by @gigibiffi84 seems close to merge, I think it would be awesome to be able to significantly reduce the size of the bundle, as well as avoid the CSP issue that we currently work around by using @cfworker/json-schema instead of ajv. Happy to send a PR from collaboratory-int/jsonforms@master...feat/core-only-entry

    14. Hi @andrewperry,
    Generally speaking this sounds like a solid plan. Do you have specific urgency on this? If the AJV paths are actually unused today in your applications, you can also workaround the issue by bundling-magic, replacing ajv and ajv-formats with empty stubs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions