feat: configureLottie for the engine's global settings, and the renderer settings the engine reads - #137
Merged
Merged
Conversation
…rer settings the engine reads
Some lottie-web settings belong to a loaded copy of the engine rather than
to one animation, so they can never be props: the prefix of the element IDs
it mints, read at every mint, and how finely it draws curves, read whenever
it builds one. `configureLottie({ idPrefix, quality })` sets both for all
three engine builds. It takes effect at once on every engine that has
loaded, and again before every load, which also puts the settings back
should anything else on the page have changed them.
IDs are prefixed by default: the base `lottie-react` plus each build's own
name, so `Lottie` and `LottieLight` on one page, two engine copies whose
counters both start at one, no longer share an ID; two copies of the
library each set a base of their own. Each build declares its engine and
name as one pair next to its hook, so the two cannot drift apart.
The renderer settings are typed as a superset of lottie-web's declarations,
adding the fields the engine reads and lottie-web leaves out: expressions
on every renderer, the element's id and content-visibility on svg and
canvas, the size on svg, the filter region on html.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #137 +/- ##
=======================================
Coverage 99.91% 99.92%
=======================================
Files 47 48 +1
Lines 1232 1253 +21
Branches 362 365 +3
=======================================
+ Hits 1231 1252 +21
Misses 1 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merged
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.
What
Some lottie-web settings belong to a loaded copy of the engine rather than to one animation, so they can never be props: the prefix of the element IDs it mints (read at every mint) and how finely it draws curves (read whenever it builds one). v2 exposed them by re-exporting the engine's player; v3 removed that with no replacement.
configureLottie({ idPrefix, quality }), exported from the barrel, sets both for all three engine builds. It takes effect at once on every engine that has loaded an animation, and again right before every load, which also puts the settings back should anything else on the page have changed them. Set it once, at startup.lottie-reactplus each build's own name (-lottie,-lottie_svg,-lottie_light). TodayLottieandLottieLighton one page are two engine copies whose counters both start at one and share every ID (the fault Unique identifier conflict in monorepo with multiple Lottie animations #117 describes); with the suffixes they cannot. Two copies of the library each set a base of their own. IDs change from__lottie_element_Ntolottie-react-lottie__lottie_element_Nfor everyone; the migration guide says so.qualitypasses through tosetQuality(low/medium/high/ a number; the engine's own default is 150 and any number above 1 restores it).fullEngine,svgEngine,lightEngine); the components import the pair, so a mispairing cannot compile.useLottieAnimation(engine, options)takes the pair.rendererSettingsmissing fromtype AnimationConfig#89: the per-rendererrendererSettingstypes are a superset of lottie-web's declarations, adding what the engine reads and lottie-web omits:runExpressionson every renderer,idandcontentVisibilityon svg and canvas,width/heighton svg (as attribute values, so strings too),filterSizeon html.configureLottiereference page, the migration guide'sLottiePlayerline, therendererSettingsreference row.Nothing runs against an engine at module scope: importing any pair still costs only that pair. Budgets after:
Lottie4.79 of 4.9 kB,useLottie3.76 of 3.85, the svg and light pairs 4.82 of 4.9; the load path now has about 100 bytes of headroom, worth knowing for the next change there.Verified
animationIDcarrieslottie-react-lottie__…andlottie-react-lottie_light__…by default, a configured base on the next load,setQualityreached at once and again before every load); the type table (the widened fields typecheck where read and are refused elsewhere).pnpm checkgreen: 488 tests, coverage 100 / 97.46 / 100 / 100, 36 pages rendered.LottieandLottieLightside by side share zero IDs where the previous build shared all four; a page callingconfigureLottie({ idPrefix: "crm", quality: "low" })mintscrm-lottie__…andcrm-lottie_light__….Closes the code half of #38, #117 and #89; their replies follow the release.