Repository navigation
Keep only the last rerender reasons, two by default - #60
Merged
Merged
Conversation
Every state change appended a RerenderReason with the previous and the next state value to the render context, and nothing ever removed them. A long-lived page therefore kept every old state value alive until the page was closed: 1000 state sets kept 1000 old values (a dataframe, a big list, ...) in memory, in both renderers. The reasons are only read for the "too many renders" error message, which showed the last two. A deque with maxlen=2 keeps that message and bounds the memory. REACTON_RERENDER_REASONS keeps more of them when debugging a render loop, and the message now shows all that are kept. test_debug_infinite_loop checked the length of the list to see that the loop ran; it now checks the error message and the render count instead. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Why
Every state change adds a
RerenderReason(prev_value, next_value)torc._rerender_needed_reasons, and nothing ever removes it. So a long-lived page keeps every old state value alive (dataframes, big lists, ...) until the page closes. This happens in both renderers, and in production today.Only the "Too many renders" error message reads this list, and it showed just the last two reasons.
What
deque(maxlen=2), so the memory stays bounded.REACTON_RERENDER_REASONS=Nkeeps more reasons when you debug a render loop. The error message now shows all the reasons it keeps, not only the last two.Tests
test_state_changes_do_not_keep_old_values_alive: does 20 state sets and checks that only a few old values stay alive. It fails without the fix, in both renderers.test_debug_infinite_loopchecks the message and the render count now, not the length of the list.test_debug_infinite_loop_more_reasons: the env var gives more reasons in the message.REACTON_FAST=0and=1.🤖 Generated with Claude Code