perf(render): stabilize cross-domain action identities via currentStateRef - #415
perf(render): stabilize cross-domain action identities via currentStateRef#415NesiciCoding wants to merge 3 commits into
Conversation
…teRef Three roster/settings actions closed over state slices owned by other domains (createStudentRubric, createGroupStudentRubrics over rubrics; getActiveGradeScale over gradeScales), so a change in the authoring domain re-identified them and re-rendered every consumer of the roster and settings domains even though their own data had not changed. They now read the fresh state through currentStateRef with empty dep arrays, keeping their identity stable: a domain value only changes when the slices it exposes change. The actions are only ever called from event handlers, so reading the ref (which is synced to the latest committed state in an effect) is never stale. Adds two regression tests asserting roster/settings consumers do not re-render when rubrics/grade scales change; both fail without the fix. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
|
Warning Review limit reached
Next review available in: 15 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesContext stability
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
|
|
@coderabbitai review |
|
|
@coderabbitai review |
|
|
@coderabbitai review |
|
|
@coderabbitai review |
|
|
@coderabbitai review |
|
|
@coderabbitai review |
|
|
@coderabbitai review |
|
|
@coderabbitai review |
|
|
@coderabbitai review |
|
|
@coderabbitai review |
|
|
@coderabbitai review |
|
…ions # Conflicts: # src/context/AppContext.test.tsx # src/context/AppContext.tsx
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
|
@CodeRabbit review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/context/AppContext.tsx`:
- Around line 1921-1925: Keep currentStateRef synchronized before descendant
layout effects run by updating it in the appropriate layout-effect phase rather
than only a passive useEffect, while preserving stable action identities. In
src/context/AppContext.tsx at lines 1921-1925, 1951-1982, and 2016-2018, ensure
createStudentRubric, createGroupStudentRubrics, and getActiveGradeScale read the
fresh snapshot. In src/context/AppContext.test.tsx at lines 693-738 and 740-773,
add regression coverage invoking these actions from a layout effect and
asserting they observe the latest rubric and grade-scale state.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 19f9f771-6aa5-4194-87ac-3d8770a761f0
📒 Files selected for processing (2)
src/context/AppContext.test.tsxsrc/context/AppContext.tsx
… fresh state The ref was synced in a passive useEffect, which fires after paint — a descendant's useLayoutEffect invoking createStudentRubric / getActiveGradeScale would read the previous commit's state (layout effects run child-first, so a provider-side effect can only ever be one commit behind). Writing the ref during render (documented latest-ref pattern) keeps it at the current render's state for every phase while preserving the stable action identities. Adds regression tests invoking the actions from a layout effect and asserting they observe the latest rubric and grade-scale state. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
Summary
Three actions exposed by the domain-split contexts close over state slices that belong to a different domain, so a change there re-identifies the action and re-renders consumers of an unrelated domain:
createStudentRubricstate.rubrics(authoring)createGroupStudentRubricsstate.rubrics,state.studentRubrics(authoring)getActiveGradeScalestate.gradeScales(authoring)They now read the fresh state through
currentStateRefwith empty dep arrays, so their identity never churns: a domain value changes only when the slices it exposes change. All three are only ever called from event handlers (or not at all in app code today), so the effect-synced ref is never stale.Tests
Two new regression tests in
AppContext.test.tsxassert that roster/settings consumers do not re-render when rubrics / grade scales change. Verified both fail against the pre-fix code and pass with the fix. FullAppContext.test.tsx(25 tests), typecheck, and lint (0 errors) all green.Relationship to other PRs
currentStateRef) — different actions, same pattern; perf(render): read whole-state actions from currentStateRef #406 targets platform-levelpushAll/dismissMigrationPrompt, this targets per-domain reader/creator actions.updateRubric→state.rubrics) were intentionally left alone: their slices already gate the same domain's value, so they cannot cause cross-domain re-renders.Summary by CodeRabbit
Bug Fixes
Tests