feat(registry): add SVG Morph component#80
Open
alejopequeno wants to merge 8 commits intomainfrom
Open
Conversation
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Import useMemo and cache loopedPaths and indices to avoid recreating arrays on every render. Update the effect to depend on the memoized loopedPaths so animations update reliably when paths change.
Implement a step prop that switches the component to controlled mode and animates directly to the target step (preserving mid- animation state). Add a useSvgMorph hook to manage step state (setStep/next/prev/isFirst/isLast), include a controlled demo, and update docs and registry metadata to advertise the new mode and hook.
Contributor
matiasperz
requested changes
Mar 2, 2026
Contributor
matiasperz
left a comment
There was a problem hiding this comment.
I think this api should be controlled by default instead of including code on it's core to auto-reproduce.
Remove auto-loop logic from the core component and hook. SvgMorph now only responds to step changes; users compose auto-play in userland. Adds guards for empty paths and out-of-bounds step.
…alejo/svg-morph # Conflicts: # pnpm-lock.yaml # public/r/registry.json # registry.json # registry/components/games/svg-morph.tsx
The merge commit accidentally shipped main's lockfile without re-running pnpm install. Also clean up the stale hooks/use-svg-morph.ts path.
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.
Result
New
svg-morphregistry component that morphs SVG pathdattributes with auto-looping. Supports multiple morph slots (each cycling through its own path states), static paths for compound shapes, and atransformprop for coordinate system conversion.registry/joyco/blocks/svg-morph.tsx— uses flubber for path interpolation + Motion for animationInstall via:
Dependencies added automatically:
flubber,motion.Media
Screen.Recording.2026-02-12.at.11.24.49.PM.mov
Greptile Summary
This PR adds a new
svg-morphregistry component that smoothly morphs SVG pathdattributes usingflubberfor interpolation andmotionfor animation. The implementation is split cleanly into anAutoMorphPath(self-looping) and aControlledMorphPath(externally driven by astepprop), along with a companionuseSvgMorphhook. The mid-animation interruption handling inControlledMorphPathis a thoughtful touch. Documentation is thorough.Two bugs were found in the component:
step: InControlledMorphPath, ifstep >= paths.length,paths[step]resolves toundefined. Both theuseRefinitialization and theuseEffectcan then passundefinedintoflubber.interpolate, throwing a runtime error. TheuseSvgMorphhook guards against this internally, but users in controlled mode who passstepdirectly are exposed.paths: InAutoMorphPath, passing an emptypathsarray causesloopedPaths = [undefined]. TheonCompletecallback always satisfiespathIndex === loopedPaths.length - 1, sosetPathIndexincrements unboundedly, freezing the UI. A simpleif (paths.length === 0) return nullguard resolves this.Confidence Score: 3/5
steptoControlledMorphPaththrows immediately via flubber, and passing an emptypathsarray toAutoMorphPathproduces an unbounded re-render loop. Both are straightforward to fix with short guard clauses.registry/joyco/blocks/svg-morph.tsx— specifically theAutoMorphPathempty-array edge case (line 31) and theControlledMorphPathout-of-bounds step handling (lines 70 and 79).Important Files Changed
Last reviewed commit: 3d93fba