Skip to content
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

Fix timing of comparison table renders #1759

Merged
merged 1 commit into from
May 24, 2022
Merged

Fix timing of comparison table renders #1759

merged 1 commit into from
May 24, 2022

Conversation

mattseddon
Copy link
Contributor

@mattseddon mattseddon commented May 24, 2022

This PR fixes an issue with the way that the comparison table rendered. We were incorrectly rendering the "missing plot" whenever a plot was added/removed from the table. More details inline.

Before

Screen.Recording.2022-05-24.at.3.36.49.pm.mov

(I only had to see this a few times before I had to fix it 🤯 )

After

Screen.Recording.2022-05-24.at.3.35.54.pm.mov

@mattseddon mattseddon added the bug Something isn't working label May 24, 2022
@mattseddon mattseddon self-assigned this May 24, 2022
@codeclimate
Copy link

codeclimate bot commented May 24, 2022

Code Climate has analyzed commit 9dd614b and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (85% is the threshold).

This pull request will bring the total coverage in the repository to 96.8% (0.0% change).

View more on Code Climate.

@@ -26,6 +27,7 @@ export const ComparisonTable: React.FC<ComparisonTableProps> = ({
}) => {
const pinnedColumn = useRef(currentPinnedColumn || '')
const [columns, setColumns] = useState<ComparisonTableColumn[]>([])
const [comparisonPlots, setComparisonPlots] = useState<ComparisonPlots>([])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[F] Because columns goes through useState and useEffect there was a timing issue between the plots data being updated and the columns being updated.

The plots data would be updated first and that would leave the column with no plot, hence the missing plot would be shown. In our project there is only one image but when there are more it would look even worse.

Please LMK if there is a more "correct React usage" way to fix this.

Thanks

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem here is that we do not want to re-render when the plots prop change. Your solution works, but in the end, it simply delays the re-render (thecomparisonPlots re-render might happen before the columns one too). So now we end up with 2 renders when the plots prop change while we simply did not want to re-render at all (once when the prop change and once when we trigger a state change after).

I do not have a solution and I do realize that I was the one who set up the thing in the first place. I think we'd need to map the columns and the plots outside of this component somehow and simply re-order in here.

We can merge this as a band-aid for now and I can either take a look after or we can pair and look at this together.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can pair. I'll set it up.

@mattseddon mattseddon marked this pull request as ready for review May 24, 2022 05:43
@mattseddon mattseddon merged commit 89d4a4c into main May 24, 2022
@mattseddon mattseddon deleted the fix-timing branch May 24, 2022 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants