Skip to content

Prevent stale content components #1477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2025

Conversation

jacbn
Copy link
Contributor

@jacbn jacbn commented May 22, 2025

Fixes an issue spotted on the SPC tests owing to identical DOM structures between sections erroneously preserving question state.

Description in the code explains this well:

Each <IsaacContent/> is assumed to be independent, not sharing state with any other. However, React will reuse components if they are the same type, have the same key (or undefined), and exist in the same place in the DOM. If two components A and B meet these criteria, if you switch from component A to component B, any e.g. useStates in B will not initialise as expected, but will retain stale data from A.

This is a problem for any structure where one of several <IsaacContent/>s are displayed, e.g. quiz sections, tabs, ... .

To avoid this, we set the key of each to its content ID.

More info here: https://react.dev/learn/preserving-and-resetting-state#same-component-at-the-same-position-preserves-state.

Copy link

codecov bot commented May 22, 2025

Codecov Report

Attention: Patch coverage is 15.00000% with 17 lines in your changes missing coverage. Please review.

Project coverage is 40.60%. Comparing base (4afc7c1) to head (313dc8f).
Report is 25 commits behind head on redesign-2024.

Files with missing lines Patch % Lines
src/app/components/content/IsaacContent.tsx 15.00% 17 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff               @@
##           redesign-2024    #1477    +/-   ##
===============================================
  Coverage          40.60%   40.60%            
===============================================
  Files                495      495            
  Lines              22087    22088     +1     
  Branches            6531     7323   +792     
===============================================
+ Hits                8968     8969     +1     
+ Misses             13082    12494   -588     
- Partials              37      625   +588     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sjd210 sjd210 merged commit 3d915c2 into redesign-2024 May 23, 2025
8 checks passed
@sjd210 sjd210 deleted the redesign/stale-content-component-state branch May 23, 2025 14:43
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