Repository navigation
Core: Avoid unused regex engine in trimmed WASM apps - #14208
Merged
Merged
Conversation
Built-in mask characters and MudBlazor's own key bindings no longer go through Regex. A trimmed WebAssembly app with a text field, select or data grid drops about 86-88 KB (brotli) of System.Text.RegularExpressions. - MaskChar.Letter, Digit and LetterOrDigit test the character with char.IsLetter, char.IsDigit and char.IsLetterOrDigit. Custom mask characters from the public constructor still match through their expression. - Components register keys through new internal literal and predicate methods on KeyMapBuilder. The public string methods keep their "/pattern/" support. - The "/./" and "/^[^ ]$/" bindings in the dialog and select become predicates that match the same keys.
…hout an expression
There was a problem hiding this comment.
Moving the built-in mask characters and MudBlazor's own key registrations off the regex engine keeps behavior the same, and all string-based key registrations in the library have been converted. The new tests cover equivalence, case sensitivity and first-match ordering. I found nothing that needs fixing before merge.
The literal registrations went through a predicate command, which cost a closure and two delegates per key. Every checkbox, switch, radio, chip and list item registers several keys, so that added up per instance. A dedicated command holds the key or key set and the action directly.
This was referenced Nov 16, 2026
This was referenced Nov 17, 2026
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.
A trimmed Blazor WebAssembly app with a MudTextField, MudSelect or MudDataGrid downloads the whole regex parser and interpreter, even when it never uses a regular expression.
Two places kept it reachable:
Regex.IsMatchon every typed character, and every text field can take a mask."/pattern/"keys.Now
MaskChar.Letter,DigitandLetterOrDigittest the character directly, and MudBlazor's components register keys through internal methods that never build a Regex.No public API changes.
RegexMask, BlockMask, MultiMask, MudHighlighter, a custom MaskChar and
"/pattern/"keys still use the engine, as before.Download size
Release publish of the
blazorwasmtemplate with default trimming,_frameworktotal, brotli.System.Text.RegularExpressions.wasm drops from about 240 KB to 22.8 KB raw; the rest serves source-generated regexes.
Pages with DateMask, the date, time and color pickers, MudAutocomplete, MudMenu, MudTabs, MudTable and MudNumericField end at the same 22.8 KB.
Behavior
DispatchAsyncby hand no longer throws in a dialog or select, and a key containing a line feed no longer matches.