Symfony UX 3.8 is out, two and a half weeks after 3.7. It adds UX Upload, a
cva() function to UX CSS, and moves the Shadcn kit of the UX Toolkit onto
the native APIs of the browser.
It is also the optimization update: 60 of its 91 pull requests make a package faster. A new benchmark application measures them against 3.6 and 3.7.
UX Upload
UX Upload is a new experimental package. Its UploadType uploads the file as
soon as it is selected, dropped or pasted, shows its progress, and keeps it
attached to the form through validation errors. Large files go in resumable
chunks.
Change FileType to UploadType and keep the rest: the field returns an
UploadedFile, so your constraints, isValid() and move() work as
before:
1 2 3 4 5 6
$builder
->add('title', TextType::class)
->add('document', UploadType::class, [
'constraints' => [new File(maxSize: '5M')],
])
;
There is no Flex recipe yet, see the installation guide. The Upload page of ux.symfony.com has six live demos.
UX CSS: Component Variants with cva()
A button with a size and a visual prop needs one set of styles per
variant. cva() describes them in one place, like the cva() of
Panda CSS, and apply() picks the right ones when the template renders:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
{# templates/components/Button.html.twig #}
{% props size = 'sm', visual = 'solid' %}
{% set button = cva(
base: { px: '3', py: '1', rounded: 'md' },
variants: {
size: {
sm: { fontSize: 'sm' },
lg: { fontSize: 'lg', px: '5' },
},
visual: {
solid: { bg: 'primary', color: 'fg' },
outline: { borderWidth: '1px' },
},
},
compoundVariants: [
{ size: 'lg', visual: 'outline', css: { borderWidth: '2px' } },
],
defaultVariants: { size: 'sm', visual: 'solid' },
) %}
<button {{ attributes.defaults({
class: button.apply({ size: size, visual: visual }),
}) }}>
{% block content %}{% endblock %}
</button>
The styles are merged, so size: 'lg' gives px_5 and not px_3. The
CSS is written when the template compiles, even for a variant chosen at
runtime. And the caller can override a property:
<twig:Button class="{{ css({ px: 'md' }) }}">.
UX CSS in PhpStorm
The Symfony plugin for PhpStorm 2026.2.315 ships the UX CSS features that
were in review when 3.7 came out. In a css() hash:
- color tokens show their color in the gutter and in the completion list;
- the completion shows the value of each token,
1remnext tomd; - Ctrl+click on a token goes to its declaration in your
ux_cssconfig, or to the default Panda token.
The plugin also completes the hashes of cva(): properties, tokens, variant
names and values. The same works for html_cva() of twig/html-extra.
UX Toolkit: The Shadcn Kit Goes Native
A dropdown menu placed with position: absolute is clipped by a card that
hides its overflow. A tooltip moved to <body> opens behind a modal dialog.
Browsers now have APIs for this, and thirteen recipes of the Shadcn kit use
them where they are supported:
popover,hover-card,dropdown-menu,select,combobox,menubar,navigation-menuandtooltipopen in the top layer with the Popover API and follow their trigger with CSS anchor positioning;dialog,alert-dialog,sheetanddraweropen and close with invoker commands, and a click on the backdrop closes them with closedby="any", all without JavaScript;- the closed panels of
accordionuse hidden="until-found", so find-in-page opens them.
The props do not change. Only the rendered HTML does, here for the Dialog recipe (classes removed):
1 2 3 4 5 6 7
<button type="button" command="show-modal" commandfor="dialog-edit_profile">
Edit profile
</button>
<dialog id="dialog-edit_profile" closedby="any">
...
</dialog>
Browsers without these APIs keep the previous behavior.
Dropzone: Messages and Transformations on Submit
Since 3.7, the files that do not match accept or exceed max_files are
left out. Nothing told the user. The Dropzone now shows a message for each
reason, announced to screen readers, and two options change or disable them:
1 2 3 4 5 6 7
->add('photos', DropzoneType::class, [
'multiple' => true,
'max_files' => 5,
'attr' => ['accept' => 'image/*'],
'accept_message' => 'Only images, please: %files%',
'max_files_message' => false,
])
A crop depends on the area the user adjusts after adding the photo, so it can
only run when the form is submitted. The new dropzone:pre-submit event
holds the submission until your promise settles:
1 2 3
this.element.addEventListener('dropzone:pre-submit', (event) => {
event.detail.waitUntil(Promise.all(event.detail.files.map((file) => cropToSelection(file))));
});
Also in this release:
- the form is held while
dropzone:pre-addlisteners process files; - image previews use object URLs, so a dozen photos no longer keep tens of megabytes of base64 in memory;
- the event detail types are exported for TypeScript;
- a custom form theme gets the container attributes and the placeholder as variables.
Some of these change the behavior: read the Dropzone UPGRADE file before updating. The Dropzone page has a live demo.
A Benchmark Application
The 3.7 post measured its gains on an ad hoc dashboard. The benchmark now lives in the repository, in apps/benchmarks: one page per package, each pushed to an extreme size.
bin/bench --against v3.6.0 --against v3.7.2 runs the three versions in one
session, on the same code, machine and load. FrankenPHP serves them,
ApacheBench loads them.
The numbers below are median requests per second in classic mode, in prod
with OPcache and preloading. Worker mode gives the same gains. The full tables
are in RESULTS.md.
Faster TwigComponent
Mounting a component no longer uses reflection or the property accessor: the work moves to the container compilation. Attributes are escaped only when they need it. And a layout with many blocks no longer slows down every component, because blocks are only converted when the content can read them.
On the dashboard page of 500 rows and 3,560 components:
| Page | 3.6 | 3.7 | 3.8 | vs 3.6 | vs 3.7 |
|---|---|---|---|---|---|
| TwigComponent dashboard | 60.3 | 77.0 | 95.4 | +58.4% | +23.9% |
Your templates must be recompiled to benefit, which a cache clear does.
Faster LiveComponent
On the server, the metadata of the LiveProps and the hook methods are written at cache warmup instead of being read by reflection on each request. In the browser, a re-render morphs the DOM without cloning it.
Typing in a nested model no longer copies all the props, and three memory leaks are fixed.
| Request | 3.6 | 3.7 | 3.8 | vs 3.6 | vs 3.7 |
|---|---|---|---|---|---|
| Dashboard page | 100.2 | 117.7 | 140.5 | +40.2% | +19.3% |
| Table search | 80.6 | 136.8 | 163.5 | +102.8% | +19.5% |
| Props dehydration | 2,525 | 2,551 | 3,282 | +30.0% | +28.6% |
The dashboard holds 100 live children. The re-render is the request sent when the user types in the search box.
Faster UX CSS
UX CSS has no row above: it did not exist in 3.6, and 3.7 has no cva(). On
the same dashboard, the css() version serves 10.9% more requests per second
than the Tailwind CSS version.
At render time, a css() call known at compile time skips the HTML escaper,
and the classes of runtime hashes are remembered. Building the stylesheet of
the benchmark app takes 12 ms instead of 28 ms.
In debug mode, a request for a CSS or JS file no longer scans every template, and a container rebuild skips the reference file when nothing changed.
Faster UX Icons
Rendering an icon skips two calls that changed nothing. On the page of 2,000 icons:
| Page | 3.6 | 3.7 | 3.8 | vs 3.6 | vs 3.7 |
|---|---|---|---|---|---|
| Icons grid | 469.5 | 470.6 | 529.8 | +12.9% | +12.6% |
ux:icons:lock and ux:icons:warm-cache now fetch the missing icons in
parallel: 256 icons from Iconify take 1 second instead of 6.
Faster UX Map
The SVG of a UX Icon is written once in the HTML instead of once per marker: a map of 2,000 markers sharing 5 icons shrinks from 1.87 MB to 1.05 MB. On the page of 2,000 markers, 100 polygons, 50 polylines and 20 circles:
| Page | 3.6 | 3.7 | 3.8 | vs 3.6 | vs 3.7 |
|---|---|---|---|---|---|
| Leaflet | 305.3 | 298.1 | 365.9 | +19.9% | +22.7% |
| Google Maps | 304.7 | 296.9 | 364.6 | +19.7% | +22.8% |
In the browser, Leaflet builds each marker icon once instead of twice, so the map is ready sooner. Google Maps parses each SVG once.
Update the PHP package and its JavaScript together: an older controller shows
0 in place of each icon.
Faster UX Translator
In the browser, trans() parsed every ICU message on each call. The parsed
messages are now kept: rendering a page with 300 calls 25 times takes 10 ms
instead of 70 ms.
At cache warmup, the TypeScript types of 6,000 messages are dumped in 230 ms instead of 1 second.
Full Changelog
- #4344 [LiveComponent] Fail the checksum check of props that JSON can't encode (@nicolas-grekas)
- #4342 [LiveComponent] Reject JS execution from download (@tnytown)
- #4337 [Toolkit][Shadcn] Show the navigation menu panels in the top layer with anchor positioning (@ker0x)
- #4338 [Toolkit][Shadcn] Place the tooltip with anchor positioning (@ker0x)
- #4336 [Toolkit][Shadcn] Show the menubar menus in the top layer with anchor positioning (@ker0x)
- #4335 [Toolkit][Shadcn] Show the combobox list in the top layer with anchor positioning (@ker0x)
- #4334 [Toolkit][Shadcn] Show the select popup in the top layer with anchor positioning (@ker0x)
- #4333 [Toolkit][Shadcn] Show the dropdown menu and its submenus in the top layer with anchor positioning (@ker0x)
- #4332 [Toolkit][Shadcn] Show the hover card in the top layer with anchor positioning (@ker0x)
- #4331 [Toolkit][Shadcn] Show the popover in the top layer with anchor positioning (@ker0x)
- #4341 [TwigComponent] Escape the classes of a component once (@Kocal)
- #4320 [Toolkit][Shadcn] Fix the tooltip staying behind a modal dialog (@Kocal)
- #4209 [Pagination] Support nullable Doctrine ORM cursor fields (@norkunas)
- #4323 [Toolkit][Shadcn] Hide the closed accordion panels with hidden="until-found" (@ker0x)
- #4327 [Toolkit][Shadcn] Use invoker commands and closedby in drawer (@ker0x)
- #4326 [Toolkit][Shadcn] Use invoker commands and closedby in sheet (@ker0x)
- #4324 [Toolkit][Shadcn] Use invoker commands, closedby and native centering in dialog (@ker0x)
- #4328 [Toolkit][Shadcn] Use invoker commands and native centering in alert-dialog (@ker0x)
- #4314 [Dropzone] Show a message for the files left out (@ker0x)
- #4313 [Dropzone] Build the attributes of the container in
DropzoneType(@ker0x) - #4315 [Dropzone] Add a
placeholderform view variable (@ker0x) - #4312 [Dropzone] Add a
dropzone:pre-submitevent to transform the files when the form is submitted (@ker0x) - #4310 [Dropzone] Hold the submission of the form while files are processed (@ker0x)
- #4308 [Dropzone] Preview the images with object URLs instead of data URLs (@ker0x)
- #4309 [Dropzone] Export the types of the
dropzone:pre-addanddropzone:rejectevent details (@ker0x) - #4307 [Dropzone] Leave out the files over
max_filesbeforedropzone:pre-add(@ker0x) - #4127 [LiveComponent] Add LiveResponse::noRender() to update the state of a component without rendering its template (@Pechynho)
- #4319 [TwigComponent] Convert outer blocks only for content that may read them (@juliangut)
- #4259 [LiveComponent] Calculate the deterministic id of a preserved child once (@Kocal)
- #4258 [LiveComponent] Capture the call stack once per deterministic id (@Kocal)
- #4321 [LiveComponent] List the hook methods of live components when the container is compiled (@Kocal)
- #4262 [LiveComponent] Compare morphed nodes without cloning them (@Kocal)
- #4263 [LiveComponent] Read a nested model without cloning all the props (@Kocal)
- #4260 [LiveComponent] Build the metadata of an object held by a
LiveProponce per class (@Kocal) - #4322 [LiveComponent] Write the metadata of the LiveProps at cache warmup (@Kocal)
- #4265 [LiveComponent] Do not retain the nodes removed by external code (@Kocal)
- #4267 [LiveComponent] Check each mutation target once per batch (@Kocal)
- #4270 [LiveComponent] Read the unsynced models once per render (@Kocal)
- #4271 [LiveComponent] Parse the
data-loadingdirectives once per element (@Kocal) - #4266 [LiveComponent] Skip the props comparison on the first
connect()(@Kocal) - #4261 [LiveComponent] Write the obscured name of each host template at cache warmup (@Kocal)
- #4269 [LiveComponent] Remove a loop with no effect in
findChildren()(@Kocal) - #4264 [LiveComponent] Keep each unsynced non-model field once (@Kocal)
- #4268 [LiveComponent] Forget the polling intervals once they are cleared (@Kocal)
- #4251 [TwigComponent] List the parameters of
mount()when the container is compiled (@Kocal) - #4254 [TwigComponent] Compile constant component names and literal props without runtime checks (@Kocal)
- #4317 [TwigComponent] Skip the value normalization for string attributes (@Pechynho)
- #3769 [Upload] Add the UX Upload package (@smnandre)
- #4318 [TwigComponent] Resolve computed methods once per component class (@Pechynho)
- #4250 [TwigComponent] Avoid copying the Twig context twice when rendering an embedded component (@Kocal)
- #4252 [TwigComponent] Read public
#[ExposeInTemplate]properties without the property accessor (@Kocal) - #4242 [TwigComponent] Make
outerBlocksfaster with a single backtrace (@Pechynho) - #4240 [TwigComponent] Print safe attribute names without the escaper (@Pechynho)
- #4241 [TwigComponent] Write plain public props without the property accessor (@Pechynho)
- #4253 [TwigComponent] Read the component stack without copying it (@Kocal)
- #4273 [Icons] Start the Iconify requests together when warming and locking icons (@Kocal)
- #4274 [Icons] Scan each template once when looking for icons (@Kocal)
- #4275 [Icons] Skip
htmlAttrValue()for string attributes (@Kocal) - #4290 [Translator] Reuse the
IntlMessageFormatinstances (@Kocal) - #4291 [Translator] Parse the plural forms of a message once (@Kocal)
- #4292 [Translator] Look up the
strtr()pattern before building it (@Kocal) - #4293 [Translator] Read the ICU message as code points once in the parser (@Kocal)
- #4294 [Translator] Print the TypeScript types once per domain (@Kocal)
- #4295 [Translator] Extract the parameters of an ICU message once (@Kocal)
- #4300 [Map] Reuse the values parsed by Stimulus (@Kocal)
- #4303 [Map] Index the elements by id on the first removal by id (@Kocal)
- #4304 [Map] Encode each element once when rendering (@Kocal)
- #4301 [Map] Forget the info windows of removed elements (@Kocal)
- #4302 [Map][Google] Parse each icon SVG once (@Kocal)
- #4299 [Map][Leaflet] Set the marker icon before adding the marker to the map (@Kocal)
- #4298 [Map] Write each UX Icon SVG once in the rendered HTML (@Kocal)
- #4289 [Css] Analyse each media query once in
AtRuleSorter(@Kocal) - #4282 [Css] Skip the reference generation when nothing changed (@Kocal)
- #4288 [Css] Do not load the template index in
dump()outside debug (@Kocal) - #4278 [Css] Remove duplicate CSS nodes without comparing all siblings (@Kocal)
- #4287 [Css] Look up properties with
isset()inStyleValidator(@Kocal) - #4286 [Css] Count variable assignments only in templates with a
settag (@Kocal) - #4285 [Css] Compute the sort keys of style rules once (@Kocal)
- #4284 [Css] Split selectors without
preg_split()(@Kocal) - #4283 [Css] Decode the Panda preset once per process (@Kocal)
- #4281 [Css] Decode the styles once when writing the stylesheet in debug (@Kocal)
- #4280 [Css] Remember the classes of each
cva()props combination (@Kocal) - #4279 [Css] Do not refresh the stylesheet on asset requests in debug (@Kocal)
- #4255 [TwigComponent] Look up the class map before the anonymous templates in
ComponentFactory::metadataFor()(@Kocal) - #4277 [Icons] Check the accessibility attributes without filtering all of them (@Kocal)
- #4243 [Css] Add the cva() function (@Kocal)
- #4239 [TwigComponent] Fix the pre-lexer ending an expression at the
}}of a nested hash (@Kocal) - #4237 [Css] Cache the classes of the css() hashes only known at runtime (@Kocal)
- #4215 [Css] Let a Twig component caller override the classes of css() (@Kocal)
- #4235 [Css] Skip escaping the classes of css() when they need none (@Kocal)
- #4214 [LiveComponent][TwigComponent] Keep the mergeable values passed to a component (@Kocal)
UX Upload and UX CSS are experimental, so their API can still change, and now is when your feedback is worth the most. If one of your pages got faster, or did not, the benchmark application is the place to show it: open an issue with the page that still costs too much.
Thank you so much for all your work! These performance improvements are so nice ❤