Skip to content

Memoize upload family observer atom in CreatePost - #20

Merged
KallynGowdy merged 1 commit into
devfrom
claude/tender-wright-tdaga7
Sep 16, 2026
Merged

KallynGowdy merged 1 commit into
devfrom
claude/tender-wright-tdaga7

Conversation

@KallynGowdy

Copy link
Copy Markdown
Contributor

Description

Wrapped the createUploadFamilyObserverAtom call in useMemo with selectedFiles as a dependency in the CreatePostForm component. This prevents unnecessary recreation of the atom on every render, which could cause performance issues and unintended side effects when the atom is used with useAtomValue.

The atom is now only recreated when selectedFiles actually changes, ensuring stable atom identity across renders and improving performance.

Checklist:

https://claude.ai/code/session_01PTvu9CJynDZnCKonytghnF

CreatePostForm created a brand-new derived jotai atom (and a new
array) on every render instead of memoizing it, which put the
component into a continuous render loop. The churn from that loop
raced with the browser's native focus/selection handling: clicking
into the editor or pressing Home/End no longer reliably moved the
caret (new text kept landing at the end instead), while Slate's
own synchronously-handled arrow keys were unaffected. Memoizing the
derived atom on selectedFiles stops the loop and fixes the focus/
cursor behavior.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PTvu9CJynDZnCKonytghnF
@KallynGowdy
KallynGowdy merged commit 1edbcd0 into dev Sep 16, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants