Reduce jQuery usage: vanilla leaf modules + opt-in Interactivity API front-end forms#452
Draft
cbravobernal wants to merge 4 commits into
Draft
Conversation
…forms Adds docs/contributing/jquery-migration-plan.md (five-phase roadmap with ecosystem-compat strategy) and executes phases 1 and 3: Phase 1 — nine leaf modules (unload + url/range/radio/button-group/ checkbox/true-false/oembed/link fields) converted to vanilla DOM internals. acf.Model events maps, helper signatures, and the public acf.* API are unchanged; jQuery stays at API boundaries and where semantics require it (oembed $.ajax abort, wpLink, beforeunload). jQuery-mock Jest tests rewritten 1:1 against real jsdom DOM. Phase 3 — opt-in @wordpress/interactivity bundle for acf_form() pages (frontend_interactivity_form setting, default off; flag-off behavior byte-identical). Server-side eligibility: simple-field forms on WP 6.5+ get the 3.6KB scf/form module with zero jQuery; complex fields fall back to the classic stack automatically. Client validation mirrors the classic contract (native constraints + acf/validate_save_post ajax), then a native POST through the untouched form-front save pipeline. New e2e spec proves the jQuery-free path logged-out, including the classic fallback. Verified: 2802 PHPUnit / 967 Jest / 258 E2E green, PHPStan clean. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
…reduction-interactivity
…reduction-interactivity
…reduction-interactivity
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR delivers the first two executable phases of a jQuery-reduction roadmap, plus the roadmap itself as a maintained document. The guiding principle, established by a module-by-module audit: the Interactivity API realistically applies to SCF's one interactive front-end surface (
acf_form()); admin code drops jQuery incrementally behind the stableacf.*API; library-bound modules (wp.media, TinyMCE, wpLink) stay as-is until core moves.1. Migration plan (
docs/contributing/jquery-migration-plan.md)Five phases with rationale, risk, ecosystem-compat strategy, and test gates per phase: vanilla-internal leaf conversions (this PR) → vanilla event delegation inside
acf.Modelpreserving the(e, $el)API → Interactivity API front-end forms (this PR) → SortableJS + native date/time inputs option → select2 → wp-components with a two-major deprecation of theacf/select2/*JS hooks.2. Phase 1: nine leaf modules converted to vanilla DOM internals
_acf-unloadand the url/range/radio/button-group/checkbox/true-false/oembed/link field models no longer use jQuery internally. The conversion is deliberately conservative:eventsmaps,$input()-style helper signatures, and method order are untouched — the publicacf.ModelAPI (which third-party add-ons consume) is unchanged; jQuery remains at the API boundary, vanilla inside..trigger('change')calls became native bubbleddispatchEventonly after verifying every listener (conditional logic, the fields event manager) catches native events; sites with jQuery-specific semantics (oembed's$.ajaxabort contract, wpLink,beforeunloadreturn-value handling) deliberately keep jQuery, each with an in-code comment.url.test.jsthat could never fail.3. Phase 3: opt-in Interactivity API bundle for front-end forms
New
scf/formInteractivity store (3.6 KB module,@wordpress/interactivityexternalized via the standard dependency-extraction module build):frontend_interactivity_formsetting (defaultfalse). With the flag off, behavior is byte-identical to today.acf/validate_save_postadmin-ajax endpoint (customacf/validate_valuefilters stay authoritative — investigation showedform-frontwp_die()s on server validation, so client pre-validation is required, exactly as the classic stack does), then a native POST through the untouchedform-front.phpsave pipeline.script[src*="jquery"]count = 0 and noacf-inputon the page, while the form renders viadata-wp-interactive, blocks on required fields, clears errors on input, and persists values. A complex-field form on the same flag correctly falls back to classic and still works.New code is SCF-owned (
scf_prefixed,includes/forms/form-front-view.php); shared-file changes total +21 flag-gated lines inform-front.php.Verification
composer test:php: OK (2802 tests, 6435 assertions — includes 14 new)npm run test:unit: 967/967 (21 new)composer test:phpstan: cleanfront-end-form.spec.ts(5 tests): passing (see checks)wp-scripts lint-jsandlint:mdclean on new filesKnown limitations (documented in the plan)
The slim bundle intentionally omits the
acf.*JS hook surface and jQuerychangetriggers — integrations that need them keep the flag off. The form-level error summary is non-dismissible. Phases 2, 4, and 5 are scoped in the plan document but not implemented here.Closes
Use of AI Tools
This PR was authored by Claude Code (Claude Fable 5) under human direction. The migration strategy, module classifications, and scope decisions were derived from a measured audit; all changes were validated by the full test battery (PHPUnit, PHPStan, Jest, Playwright) including a purpose-built e2e spec proving the jQuery-free path.