Repository navigation
Conversation
TextMorph and MorphController gain configure(), which applies new options to the live instance: ease and duration are resolved again, the reduced-motion listener is added or removed, and the debug attribute is toggled. The React, Vue and Svelte wrappers attach once per element and pass option changes through it, so a prop change no longer cancels the running morph and rebuilds the text. needsRecreate() had no caller and is removed.
|
@Bewinxed is attempting to deploy a commit to the Lochie Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
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.
Problem
MorphController.attach()destroys the currentTextMorphand builds a new one. The Svelte wrapper calls it from an$effectkeyed onserializeConfig(options), and the React and Vue wrappers do the same with their own config keys. So any option change on a mountedTextMorph(disabled,duration,ease,debugand the rest) tears the morph down.destroy()cancels every animation on the element throughelement.getAnimations()and drops the accessible copy, the root attribute and the stylesheet reference, and the new instance replaces the element's contents and lays the text out again.On a page with many morphs whose options follow app state, this gets expensive. In a trace of a design-system page full of morphing labels,
destroytook 307 ms over about 15 s, 274 ms of it ingetAnimations.needsRecreate()looks like it was meant to prevent this, but nothing calls it.What changed
TextMorphgetsconfigure(options), and the constructor now calls it, so one place turns options into the instance's settings. It merges the given options over the current ones, and an option passed asundefinedreturns to its default, as in the constructor. The options the constructor used to apply once now update live:easeanddurationare resolved again, so a spring still computes its own duration.respectReducedMotionadds the media-query listener when turned on and removes it when turned off.debugtogglestorph-debugon an instance that is already set up. One that isn't set up yet gets it insetup(), as before.disabledis read byisDisabled()on each update, so the next update takes the plain-text path it already takes when reduced motion turns on mid-life. A running morph finishes and settles first, and turningdisabledoff sets the instance up on the next update.locale,decimals,numbers,scaleand the callbacks were already read when a morph runs.MorphController.configure(options)passes options to the live instance and queues the last value again. That does nothing unless a newlocaleordecimalsformats a number differently, in which case it morphs to the new format, which a rebuild would also have shown.needsRecreate()and the controller'sconfigKeyfield are removed.serializeConfig()stays because the React hook keys its effect on it.Each wrapper now attaches once per element and sends option changes through
configure(). In Svelte, one effect attaches (readingoptionsthroughuntrack) and another callsconfigure(options); callback props now reach the morph instead of staying as they were at attach time. In React, one effect attaches on mount and another callsconfigure()when the config key changes; callbacks still go through the ref, andonAnimationCancelnow does too. In Vue, one computedoptionsfeedsattach()when the element ref changes andconfigure()whenoptionschanges.The changeset is a patch, with the
needsRecreate()removal listed under Breaking becauseMorphControlleris exported.Testing
configure.test.tscovers the engine and the controller:destroy()and keeps its nodes;durationandease, and a spring given later resolves as the constructor would resolve it;undefinedgoes back to its default;disabled: truemakes the next update a plain-text swap with no animations, anddisabled: falsemorphs again;debugturns the outline attribute on and off;respectReducedMotionadds the media-query listener once (a second call adds no other), removes it when turned off, anddestroy()leaves none;MorphController.configure()keeps the same instance, and a newlocalereformats the current number (1,234.5to1.234,5).vue/__tests__/TextMorph.test.tsmounts the Vue component, changesduration,easeanddebug, and checks that the morph isn't destroyed and the next text change animates with the new duration.All 11 new tests fail against
main. The React and Svelte wrappers have no tests here: with no vitest config, the React wrapper's JSX doesn't parse in tests and.sveltefiles don't compile there. I compiled the Svelte component withsvelte/compilerinstead, with no warnings.pnpm test(428 passed),pnpm typecheck,pnpm lintandpnpm buildpass. The lint warnings are all insite/, the same onesmainhas.Related
#62 stopped the React wrapper rebuilding its controller on every render. This does the same for option changes in all three wrappers.
#73 edits nearby lines:
serializeConfig()incontroller.ts(scaleandnumbersout,pluginsin) and the props andoptionsblock inTextMorph.svelte. Whichever lands second needs a small rebase, andscaleandnumberswould come out of the option list inconfigure.test.ts. Under #73 a plugin sets up CSS, per-morph state and a teardown when the instance is built, soconfigure()shouldn't swap plugins on a live instance; apluginschange should still go throughattach().