Skip to content

perf(render): stabilize cross-domain action identities via currentStateRef - #415

Open
NesiciCoding wants to merge 3 commits into
mainfrom
perf/stable-domain-actions
Open

perf(render): stabilize cross-domain action identities via currentStateRef#415
NesiciCoding wants to merge 3 commits into
mainfrom
perf/stable-domain-actions

Conversation

@NesiciCoding

@NesiciCoding NesiciCoding commented Aug 11, 2026

Copy link
Copy Markdown
Owner

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:

Action Domain Leaked dep Effect
createStudentRubric roster state.rubrics (authoring) any rubric change re-renders every roster consumer
createGroupStudentRubrics roster state.rubrics, state.studentRubrics (authoring) same
getActiveGradeScale settings state.gradeScales (authoring) any grade-scale change re-renders every settings consumer (incl. always-mounted Topbar/Sidebar)

They now read the fresh state through currentStateRef with 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.tsx assert 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. Full AppContext.test.tsx (25 tests), typecheck, and lint (0 errors) all green.

Relationship to other PRs

Summary by CodeRabbit

  • Bug Fixes

    • Improved context updates so roster and settings views remain stable when rubrics or grade scales change.
    • Preserved grouped rubric creation while preventing unnecessary component re-rendering.
  • Tests

    • Added coverage confirming that unrelated consumers do not re-render during rubric and grade-scale updates.

…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>
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@NesiciCoding, you've reached your PR review limit, so we couldn't start this review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f4b460af-18ed-49f6-a4dd-c3db0b1d6d1b

📥 Commits

Reviewing files that changed from the base of the PR and between 08a1b03 and 68a4e4f.

📒 Files selected for processing (2)
  • src/context/AppContext.test.tsx
  • src/context/AppContext.tsx
📝 Walkthrough

Walkthrough

AppContext now reads current state through currentStateRef for stable callbacks. Tests verify that rubric and grade-scale changes do not re-render unrelated roster or settings consumers.

Changes

Context stability

Layer / File(s) Summary
Stable state access
src/context/AppContext.tsx
createGroupStudentRubrics and getActiveGradeScale read current state through currentStateRef. Callback dependencies no longer include captured state for rubric creation.
Rendering regression tests
src/context/AppContext.test.tsx
Tests verify that roster consumers remain stable after rubric creation and settings consumers remain stable after grade-scale creation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: claude

Poem

I nibbled the ref and the callbacks stayed still,
Rubrics hopped neatly with no extra thrill.
Roster leaves rested, settings stayed bright,
Tests watched the render count just right.
A stable context—what a fine carrot delight!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the performance change that stabilizes cross-domain action identities via currentStateRef.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/stable-domain-actions

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@NesiciCoding

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@NesiciCoding

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@NesiciCoding

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@NesiciCoding

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@NesiciCoding

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@NesiciCoding

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@NesiciCoding

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@NesiciCoding

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@NesiciCoding

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@NesiciCoding

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@NesiciCoding

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@NesiciCoding

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Base automatically changed from perf/appcontext-domain-split-wave5 to main August 12, 2026 09:05
…ions

# Conflicts:
#	src/context/AppContext.test.tsx
#	src/context/AppContext.tsx
@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 80.23% (🎯 65%) 10996 / 13705
🟢 Statements 78.29% (🎯 65%) 12556 / 16037
🟢 Functions 70.77% (🎯 60%) 3897 / 5506
🟢 Branches 69.44% (🎯 58%) 9345 / 13456
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/context/AppContext.tsx 70.31% 56.89% 53.54% 69.54% 243-244, 301, 536, 558, 566, 579, 588, 898-905, 910, 1353, 1363-1415, 1439-1442, 1480-1487, 1544-1545, 1555-1644, 1654, 1658-1662, 1663-1664, 1678-1681, 1688-1690, 1699-1705, 1732-1763, 1789, 1790, 1796, 1799, 1800, 1802, 1803, 1804, 1805, 1806, 1807, 1808, 1809, 1814, 1816, 1817, 1818, 1823, 1825, 1826, 1827, 1828, 1829, 1830, 1831, 1846, 1847, 1866-1867, 1898-1899, 1918, 2054-2062, 2073-2082, 2088-2091, 2096, 2099, 2101, 2106, 2112-2119, 2124, 2127, 2131-2138, 2176-2180, 2193-2194, 2219, 2231-2234, 2238, 2241, 2244, 2247, 2250, 2254, 2258, 2263, 2267-2270, 2273-2276, 2279-2282, 2285-2288, 2291-2294, 2297-2302, 2307-2310, 2313, 2316, 2320-2322, 2327, 2330, 2333, 2336, 2341-2343, 2346, 2349, 2352, 2357, 2360, 2366-2390, 2397-2398, 2402, 2406-2412, 2417, 2421-2429, 2433, 2437, 2441-2442, 2446-2447, 2451, 2455, 2459-2460, 2464, 2467, 2469, 2473, 2477, 2481, 2484, 2486, 2490, 2494-2495, 2498, 2500, 2504, 2508, 2512, 2516-2517, 2521, 2525, 2529, 2533, 2536, 2538, 2544-2545, 2549-2550, 2554-2556, 2560, 2564, 2568, 2572-2586, 2592-2607, 2618, 2620, 2623, 2625-2626, 2630, 2634, 2638-2639, 2643, 2648-2661
Generated in workflow #1201 for commit 68a4e4f by the Vitest Coverage Report Action

@NesiciCoding

Copy link
Copy Markdown
Owner Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3332274 and 08a1b03.

📒 Files selected for processing (2)
  • src/context/AppContext.test.tsx
  • src/context/AppContext.tsx

Comment thread src/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>
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.

1 participant