Editor: move AuthorsSelect init side effects to useEffect#175
Editor: move AuthorsSelect init side effects to useEffect#175dknauss wants to merge 2 commits intohumanmade:developfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e8b7b9179e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
src/components/AuthorsSelect.tsx
Outdated
| }; | ||
| } | ||
|
|
||
| hasInitializedSelection.current = true; |
There was a problem hiding this comment.
Delay initialization until author IDs are available
This unconditional hasInitializedSelection.current = true runs even when currentAuthorIDs is not yet available (for example, initially undefined/empty before editor data finishes loading), so later effect executions immediately return at the top guard and never hydrate selection from preload or API. In that delayed-load scenario the selector remains empty despite the post having authors, which is a regression from the previous logic that retried initialization once IDs appeared.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Interesting catch! A little over-zealous since setting hasInitializedSelection.current = true at line 105 (the final fallback at the bottom of the effect) means that if currentAuthorIDs is initially undefined/empty, the guard at the top will prevent later hydration when IDs arrive.
But — there's a possible edge case: if currentAuthorIDs is initially [] (empty array, not undefined), the effect falls through to line 105, sets the ref to true, and then when real IDs arrive, the guard blocks re-initialization. That's a real (if unlikely) race condition depending on how the block editor hydrates the store.
The fix is setting the ref to true inside the two branches that actually initialize (preload match and API fetch), removing line 105 entirely.
Fixed in c7a772e. The fallback guard is removed so the effect re-runs until real data arrives.
The fallback `hasInitializedSelection.current = true` at the bottom of the useEffect fired when currentAuthorIDs was initially empty, blocking later re-runs from hydrating the selection once real data arrived. The ref is now only set to true inside the two branches that actually perform initialization (preload match and API fetch), so the effect safely re-runs until data is available. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
What this does
Moves initial author-selection setup out of render and into
useEffect.What this fixes
Prevents render-time state updates and render-time async fetch work in
AuthorsSelect, which can lead to repeated initialization and unstable editor behavior.What this changes
useEffectWhy
The current component mutates state and starts async work while rendering. React components should keep render pure and perform this setup in effects.
Scope
This PR is intentionally narrow with only front-end concerns.
Included:
src/components/AuthorsSelect.tsxNot included: