Repository navigation
3.0.0.beta1
Pre-releaseHighlights
The first beta of Phlex 3. Compared with 2.4.3, the big change is a new compiler. It turns your components into faster Ruby and renders exactly the same output. Rendering without it is faster too, and there's an optional C extension for attributes.
The compiler is on by default
Every component compiles the first time it renders. The compiler rewrites your templates into plain Ruby string appends. A compiled component renders byte for byte what it would have uncompiled. If the compiler can't reproduce some code exactly, it leaves that code uncompiled and the component keeps rendering as normal. (#1001, #1009, #1093)
- Turn it off for a class and its subclasses with
compile false, or back on withcompile true. A gem can opt its own components out without the app's choice affecting them. Phlex::Compiler.disable!turns it off everywhere.Phlex::Compiler.precompile(component)compiles a component ahead of time, for example at boot before forking.Phlex::Compiler.forget(component)is for code reloaders.Phlex::Compiler.source(component)shows the Ruby a component compiles to, andexplaintells you what didn't compile and why. (#1094)- Subclasses loaded later, modules included afterwards and re-registered elements trigger a recompile, so they take effect just as they would uncompiled. Files edited after loading are refused rather than compiled. (#1009, #1070, #1102)
- Mixin methods aren't compiled yet. That only costs speed. (#1069)
Faster rendering, even without the compiler
- Fewer allocations when generating attributes, and a larger default attribute cache (1 MiB). (#990, #991, #1005)
- Faster attribute cache misses, CSV, Kit calls,
captureand component allocation. (#1065) - Component rendering no longer leaves YJIT on every render. (#1103)
Phlex::SGML.newis no longer overridden, so Ruby 4 can inline it. (#1104)FIFOCacheStorehits on plain data no longer deserialise on every read, about 30% faster forcache. (#1107)
Optional C extension
Phlex now includes a C attribute serialiser. It's built when you install the gem on CRuby 4.0 or later. Anywhere it can't be built (JRuby, TruffleRuby, older Rubies, no compiler), installation carries on and Phlex uses Ruby. Set PHLEX_NATIVE=false at install time to skip it. (#1068, #1095)
Ractors
Components render on any Ractor, including compiled components, kits, tag, SVG, fragments, cache and CSV, with the same output as the main Ractor. Compiling, defining components and register_element still happen on the main Ractor. (#1064, #1067)
Also new
call(rerenderable: true)lets you render the same component instance more than once. (#1076)parentis public and returns the component that rendered this one, ornil. (#1090)with_contentbuilds a component that keeps its content block, e.g.Card.with_content(title:) { "content" }. (#1104)FIFOCacheStore#fetchaccepts cache options such asexpires_in:, so it works anywhereRails.cachedoes. The options are ignored. (#1040)- The Ruby LSP add-on supports ruby-lsp 0.27, reads custom
tag:names, and follows Kit calls likeCard(title:)for go-to-definition and hover. (#1091)
Breaking changes
- Ruby 3.3 or later is required. (#1071)
newno longer takes a content block. A block passed tonewgoes toinitializelike any Ruby class. Pass content torenderorcall, or usewith_content. Kit calls likeCard { }are unchanged. (#1104)Phlex::CSVdeprecations are removed. A customyielderraises; rename it toaround_rowand changeyieldtosuper. A CSV that only definesview_templateno longer uses it as the row template. (#1090)- A fragment that starts inside an open fragment of the same name raises
Phlex::ArgumentError. Sibling fragments can still share a name. (#1082) plainraises when given a block. It used to ignore it. (#1028)- Rendering a class that isn't a component raises instead of rendering nothing. (#1039)
- Custom element names must start with a lowercase letter, as the HTML spec requires. (#1052)
- An empty attribute name raises. (#1071)
FIFOCacheStorestores values with Marshal instead of JSON, and hits on plain data return a frozen copy. Code that mutates a cached value gets aFrozenError. (#1062, #1107)- New dependencies:
refract ~> 2.0.0,erb >= 5.0.2(the first with a Ractor-safeERB::Escape) andrake(to build the C extension).
Fixes
- With phlex-rails,
raw(safe(...)), a block returningsafe(...)and output helpers likecsrf_meta_tagsare no longer lost. A block's return value is no longer added as output after the block wrote something. (#1056) mixmerges Symbol tokens, and string keys ending in!are left as they are. (#1058, #1030)falseis skipped inclass:andstyle:collections, socond && "token"works. (#1059)Date,Timeandto_hvalues work in nested attributes likedata:. (#1043)- Empty style entries are skipped, and an empty
styleattribute is left out. Leading empty tokens no longer add a separator, e.g. insrcset. (#1047, #1044) safe(...)attribute values hit the attribute cache. The cache now matches attribute order and safety exactly. (#1060, #1071)- Nested attribute hashes can't spell an unsafe attribute name. Character references to invalid code points decode to U+FFFD instead of raising. (#1071)
tagfinds elements registered on component classes, normalisesimg,linkandinputattributes, and closes its tag when content raises. (#1063, #1033, #1032)- Fragments are found inside
whitespaceandcommentblocks, keep working after an exception, and are tracked correctly withcaptureand nested caches. Symbol and String fragment names select the same fragment. (#1061, #1035, #1038, #1079, #1027) - Implicit block output survives a
flush. (#1036) FIFOCacheStorehandles non-UTF-8 content, and FIFO caches no longer keep empty values. (#1062, #1031)Phlex::CSVclears a partial row left by a previous call that raised. (#1041)- No more Ruby 4.0 block warnings from
before_templateandafter_template, or verbose warnings when loading elements. (#986, #994)
What's Changed
- Fix Kit rendering context error when render? is false by @stephannv in #980 (also in 2.4.3)
- Require 'date' so attribute serialization works without Rails by @mikolajczu in #981 (also in 2.4.3)
- Fix Ruby 4.0 warning in default before_template and after_template by @ErnaneJ in #986
- Update documentation with forum by @solojavier in #987
- perf: avoid allocations when generating attributes by @mhenrixon in #990
- perf: raise the attribute cache floor to 1 MiB by @mhenrixon in #991
- Hash attribute cache keys once and handle nil-key cache misses by @joeldrapper, building on #992 by @mhenrixon, in #1005
- Define kit methods from a string so they can be called from any Ractor by @joeldrapper, building on #1057 by @mhenrixon, in #1064
- Render components on any Ractor by @joeldrapper, building on #1055 by @mhenrixon, in #1067
- Rewrite the compiler for exact runtime equivalence by @joeldrapper in #1001
- Make the compiler invisible by @joeldrapper in #1009
- Add phlex-native, a C extension for attribute serialisation by @joeldrapper in #1068
- Build the C extension as part of phlex, only where it can be built by @joeldrapper in #1095
- Allow components to be rendered again with
call(rerenderable: true)by @joeldrapper in #1076 - Phlex 3 cleanups: remove CSV deprecations, make
parentpublic, tidy repo root by @joeldrapper in #1090 - Ruby LSP add-on: fix 0.27 and custom tags, follow Kit calls by @joeldrapper in #1091
- Compile components by default, with an inherited
compilesetting by @joeldrapper in #1093 - Add
Phlex::Compiler.sourceto show the Ruby a component compiles to by @joeldrapper in #1094 - Stop overriding
Phlex::SGML.new, addwith_contentby @joeldrapper in #1104 - Return a frozen copy from
FIFOCacheStorehits instead of loading one by @joeldrapper in #1107
Plus many more compiler, performance and bug-fix PRs by @joeldrapper, listed in the full changelog.
New Contributors
- @mikolajczu made their first contribution in #981
- @ErnaneJ made their first contribution in #986
- @solojavier made their first contribution in #987
- @mhenrixon made their first contribution in #990
Full Changelog: 2.4.3...3.0.0.beta1