[6.x] Port matrix blocks#19276
Open
brianjhanson wants to merge 7 commits into
Open
Conversation
The JS action clients have always sent X-Registered-Asset-Bundles / X-Registered-Js-Files headers, but nothing server-side read them, so every XHR-rendered fragment (Matrix add-block, slideouts, etc.) shipped the entire page asset stack. Re-executing those bundles against a live page threw ([exposes-loader] Garnish global) and clobbered JS class identity, leaving XHR-delivered fragments like nested Matrix inputs without working JS. RegisteredClientAssets now mirrors Craft 5's mechanism: it parses the headers, InternalAssetRegistry and HtmlStack::jsFile() skip re-shipping anything the browser reported (crc32 hashes, same format as the legacy view's resource hashes), and non-ajax body-end renders emit a standalone script recording what was registered onto Craft.registeredAssetBundles/ registeredJsFiles for the clients to echo back. A standalone tag, not part of the shared inline-JS blob, so an unrelated script error can't prevent the recording. Verified against the dev site: a Matrix create-entry response drops from 57.7KB with 16 re-shipped bundle scripts to 22.5KB with none, while keeping the new block's init JS. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Craft.MatrixInput and Craft.MatrixInput.Entry (1,500 lines of jQuery in
the legacy matrix webpack bundle) become resources/js/modules/matrix:
MatrixInput + MatrixEntry controller classes on @craftcms/garnish Base, a
<craft-matrix-input> custom element, WeakMap registries, and an index.ts
shim that keeps the PHP-emitted boot script and flash JS working
(constructor-compatible global, statics, .Entry).
Legacy-runtime seams are typed and centralized in interop.ts:
Garnish.Select, Craft.Tabs, Craft.FormObserver, and Craft.ElementEditor
have no modern ports yet and are reached through the page globals, and
the instances mirror themselves into jQuery data because PHP-emitted
snippets read $(el).data('matrix'/'entry'). Velocity animations become
Web Animations API calls honoring reduced motion.
MatrixAsset no longer ships the legacy bundle; the module is loaded by
both Vite entrypoints. Verified end-to-end on the dev site: real-click
add on the top-level field and on a nested matrix delivered via XHR
(correct namespace chains, booted controllers), collapse/expand with
preview text and localStorage persistence, action-menu state, drag-sort
registration.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Matrix::blockInputHtml() now wraps the input template in the module's custom element (entry-types / input-name-prefix / settings attributes, written fully namespaced) instead of emitting a `new Craft.MatrixInput` boot script. The min-entries auto-add JS becomes an `addDefaultEntries` setting handled by the MatrixInput class after its afterInit event; the server-side DeltaRegistry reset stays put. Nested matrix inputs arriving in XHR-rendered block HTML now boot themselves on insertion via custom-element upgrade, with no dependency on the response's executed JS. Also aligns the module's imports with this branch's @craftcms/ui package name (the cherry-picks were authored pre-rename). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Clearing every entry posts `fields[handle]=''`, the Yii-era sentinel the normalize path matches with `$value === ''` to override the query result to empty. Under Laravel that sentinel never arrives: the global ConvertEmptyStringsToNull middleware turns it into null, which fell through to the lazy-load branch — so the field looked unchanged and NestedElementManager never deleted anything, silently resurrecting the removed entries on save. normalizeValueFromRequest(null) now means "all entries removed", which is unambiguous because delta only applies request values for fields that were actually modified. Outside a request, null still lazy-loads. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
📚 Storybook previews@craftcms/ui — open Storybook No changed components detected in this Storybook. resources/js — open Storybook No changed components detected in this Storybook. |
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.
Refactors the
MatrixInputand related files into the new code style. There is a newcraft-matrix-inputweb component that will instantiate theMatrixInputclass which is a port from the legacyCraft.MatrixInputcode but in typescript and without jQuery.A compatibility shim is provided by the
modules/matrix/indexfile and is imported into thelegacybundle for the twig code to use.Related issues
Fixes #19161