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: remove react-hooks linter suppression #8051

Merged
merged 1 commit into from
Jan 3, 2025

Conversation

stipsan
Copy link
Member

@stipsan stipsan commented Dec 13, 2024

Description

Suppressing the linter on react-hooks/exhaustive-deps causes React Compiler to bail, as it can no longer determine if the optimization it plans to do will preserve the original behavior of how often and when useEffect hooks will fire.
It's also a bit dangerous to leave in the codebase as what may have started off as omitting a single value from the dependencies array, can over time lead to other values being omitted that would otherwise been caught be the linter.
For example DocumentListPaneContent have had its linter suppression for a long long time, and since then we have added const {t} = useTranslation(structureLocaleNamespace) and t should be a dependency, but it's not.

This PR removes all of them, and in the case of useEffect the useEffectEvent ponyfill is used to preserve the original intent of only having the effect fire when specific dependencies have changed, while no longer suppressing the linter.

What to review

Is there enough context?

Testing

Existing tests are sufficient?

Notes for release

Removed react-hooks/exhaustive-deps ESLint suppressions, allowing React Compiler to auto-memoize components that were previously skipped over.

Copy link

vercel bot commented Dec 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
page-building-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 3, 2025 0:56am
performance-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 3, 2025 0:56am
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 3, 2025 0:56am
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 3, 2025 0:56am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Jan 3, 2025 0:56am

Copy link
Contributor

No changes to documentation

Copy link
Contributor

github-actions bot commented Dec 13, 2024

Component Testing Report Updated Jan 3, 2025 12:48 PM (UTC)

❌ Failed Tests (1) -- expand for details
File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 1m 9s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 12s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 38s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 50s 11 7 0
formBuilder/inputs/PortableText/copyPaste/CopyPasteFields.spec.tsx ✅ Passed (Inspect) 0s 0 12 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 25s 6 0 0
formBuilder/inputs/PortableText/DisableFocusAndUnset.spec.tsx ✅ Passed (Inspect) 14s 3 0 0
formBuilder/inputs/PortableText/DragAndDrop.spec.tsx ✅ Passed (Inspect) 26s 6 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 1m 7s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 27s 21 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 40s 18 0 0
formBuilder/inputs/PortableText/PresenceCursors.spec.tsx ✅ Passed (Inspect) 12s 3 9 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 26s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ❌ Failed (Inspect) 2m 23s 20 0 1
formBuilder/tree-editing/TreeEditing.spec.tsx ✅ Passed (Inspect) 0s 0 3 0
formBuilder/tree-editing/TreeEditingNestedObjects.spec.tsx ✅ Passed (Inspect) 0s 0 3 0

Copy link
Contributor

github-actions bot commented Dec 13, 2024

⚡️ Editor Performance Report

Updated Fri, 03 Jan 2025 12:49:24 GMT

Benchmark reference
latency of sanity@latest
experiment
latency of this branch
Δ (%)
latency difference
article (title) 27.0 efps (37ms) 27.0 efps (37ms) +0ms (-/-%)
article (body) 71.9 efps (14ms) 72.5 efps (14ms) -0ms (-/-%)
article (string inside object) 26.3 efps (38ms) 27.8 efps (36ms) -2ms (-5.3%)
article (string inside array) 24.4 efps (41ms) 25.6 efps (39ms) -2ms (-4.9%)
recipe (name) 55.6 efps (18ms) 58.8 efps (17ms) -1ms (-5.6%)
recipe (description) 62.5 efps (16ms) 66.7 efps (15ms) -1ms (-6.3%)
recipe (instructions) 99.9+ efps (5ms) 99.9+ efps (5ms) +0ms (-/-%)
synthetic (title) 20.2 efps (50ms) 21.3 efps (47ms) -3ms (-5.1%)
synthetic (string inside object) 20.8 efps (48ms) 20.8 efps (48ms) +0ms (-/-%)

efps — editor "frames per second". The number of updates assumed to be possible within a second.

Derived from input latency. efps = 1000 / input_latency

Detailed information

🏠 Reference result

The performance result of sanity@latest

Benchmark latency p75 p90 p99 blocking time test duration
article (title) 37ms 41ms 53ms 486ms 761ms 10.5s
article (body) 14ms 16ms 20ms 69ms 77ms 5.1s
article (string inside object) 38ms 39ms 42ms 89ms 272ms 6.8s
article (string inside array) 41ms 44ms 49ms 230ms 245ms 7.2s
recipe (name) 18ms 19ms 22ms 39ms 0ms 6.6s
recipe (description) 16ms 18ms 22ms 30ms 0ms 4.4s
recipe (instructions) 5ms 7ms 8ms 9ms 0ms 3.1s
synthetic (title) 50ms 51ms 56ms 298ms 462ms 12.4s
synthetic (string inside object) 48ms 50ms 56ms 265ms 352ms 8.1s

🧪 Experiment result

The performance result of this branch

Benchmark latency p75 p90 p99 blocking time test duration
article (title) 37ms 41ms 55ms 486ms 776ms 10.1s
article (body) 14ms 15ms 17ms 37ms 52ms 4.6s
article (string inside object) 36ms 38ms 44ms 170ms 148ms 6.6s
article (string inside array) 39ms 41ms 45ms 144ms 131ms 6.6s
recipe (name) 17ms 19ms 19ms 37ms 0ms 7.0s
recipe (description) 15ms 16ms 19ms 40ms 0ms 4.3s
recipe (instructions) 5ms 7ms 8ms 10ms 0ms 3.1s
synthetic (title) 47ms 49ms 52ms 129ms 112ms 11.8s
synthetic (string inside object) 48ms 51ms 56ms 111ms 741ms 7.7s

📚 Glossary

column definitions

  • benchmark — the name of the test, e.g. "article", followed by the label of the field being measured, e.g. "(title)".
  • latency — the time between when a key was pressed and when it was rendered. derived from a set of samples. the median (p50) is shown to show the most common latency.
  • p75 — the 75th percentile of the input latency in the test run. 75% of the sampled inputs in this benchmark were processed faster than this value. this provides insight into the upper range of typical performance.
  • p90 — the 90th percentile of the input latency in the test run. 90% of the sampled inputs were faster than this. this metric helps identify slower interactions that occurred less frequently during the benchmark.
  • p99 — the 99th percentile of the input latency in the test run. only 1% of sampled inputs were slower than this. this represents the worst-case scenarios encountered during the benchmark, useful for identifying potential performance outliers.
  • blocking time — the total time during which the main thread was blocked, preventing user input and UI updates. this metric helps identify performance bottlenecks that may cause the interface to feel unresponsive.
  • test duration — how long the test run took to complete.

// Task is updated on every change, wait until the revision changes to update the activity log.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [fetchAndParse, task._rev])
handleFetchAndParse(task._rev)
Copy link
Member Author

Choose a reason for hiding this comment

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

Sending the task._rev here is just to make it a valid useEffect dependency in the eyes of eslint-plugin-react-hooks/exhaustive-deps as well as the React Compiler.

Comment on lines -250 to -252
// Explicitly don't include `noDocumentsContent` in the deps array, as it's
// causing a visual bug where the "No documents" message is shown for a split second
// when clearing a search query with no results
Copy link
Member Author

Choose a reason for hiding this comment

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

I can't reproduce this issue mentioned here, so I think we're good.
In any case, it's not ideal that what initially was just noDocumentsContent being exempt has eventually led to other deps, t and paneTitle, being accidentally omitted.
It demonstrates why it's risky to suppress the linter to begin with 😅

Copy link
Member

Choose a reason for hiding this comment

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

Good call, glad to get rid of hacks like this

@bjoerge bjoerge requested review from a team as code owners December 20, 2024 10:29
@stipsan stipsan force-pushed the remove-document-list-pane-content-linter-suppression branch from d5e60d5 to 7e05a33 Compare December 20, 2024 14:16
@stipsan stipsan force-pushed the remove-document-list-pane-content-linter-suppression branch from 7e05a33 to d6aa840 Compare December 20, 2024 18:38
Comment on lines -250 to -252
// Explicitly don't include `noDocumentsContent` in the deps array, as it's
// causing a visual bug where the "No documents" message is shown for a split second
// when clearing a search query with no results
Copy link
Member

Choose a reason for hiding this comment

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

Good call, glad to get rid of hacks like this

@stipsan stipsan added this pull request to the merge queue Jan 3, 2025
Merged via the queue into next with commit 1d25b3c Jan 3, 2025
55 of 56 checks passed
@stipsan stipsan deleted the remove-document-list-pane-content-linter-suppression branch January 3, 2025 13:06
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