-
Notifications
You must be signed in to change notification settings - Fork 467
feat/changelog-display-navigation #2814
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
Conversation
✅ Deploy Preview for hyprnote-storybook canceled.
|
✅ Deploy Preview for hyprnote canceled.
|
✅ Deploy Preview for howto-fix-macos-audio-selection canceled.
|
| useEffect(() => { | ||
| const key = Object.keys(changelogFiles).find((k) => | ||
| k.endsWith(`/${version}.mdx`), | ||
| ); | ||
|
|
||
| if (!key) { | ||
| setLoading(false); | ||
| return; | ||
| } | ||
|
|
||
| changelogFiles[key]().then((raw) => { | ||
| const markdown = stripImageLine(stripFrontmatter(raw as string)); | ||
| setContent(md2json(markdown)); | ||
| setLoading(false); | ||
| }); | ||
| }, [version]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memory leak and race condition: The async operation in useEffect has no cleanup logic. If the component unmounts before the promise resolves, setContent and setLoading will be called on an unmounted component, causing React warnings and potential memory leaks. Additionally, if version changes rapidly, multiple promises can be in-flight and the last one to resolve wins, not necessarily matching the current version.
useEffect(() => {
let cancelled = false;
const key = Object.keys(changelogFiles).find((k) =>
k.endsWith(`/${version}.mdx`),
);
if (!key) {
setLoading(false);
return;
}
changelogFiles[key]().then((raw) => {
if (cancelled) return;
const markdown = stripImageLine(stripFrontmatter(raw as string));
setContent(md2json(markdown));
setLoading(false);
});
return () => {
cancelled = true;
};
}, [version]);| useEffect(() => { | |
| const key = Object.keys(changelogFiles).find((k) => | |
| k.endsWith(`/${version}.mdx`), | |
| ); | |
| if (!key) { | |
| setLoading(false); | |
| return; | |
| } | |
| changelogFiles[key]().then((raw) => { | |
| const markdown = stripImageLine(stripFrontmatter(raw as string)); | |
| setContent(md2json(markdown)); | |
| setLoading(false); | |
| }); | |
| }, [version]); | |
| useEffect(() => { | |
| let cancelled = false; | |
| const key = Object.keys(changelogFiles).find((k) => | |
| k.endsWith(`/${version}.mdx`), | |
| ); | |
| if (!key) { | |
| setLoading(false); | |
| return; | |
| } | |
| changelogFiles[key]().then((raw) => { | |
| if (cancelled) return; | |
| const markdown = stripImageLine(stripFrontmatter(raw as string)); | |
| setContent(md2json(markdown)); | |
| setLoading(false); | |
| }); | |
| return () => { | |
| cancelled = true; | |
| }; | |
| }, [version]); | |
Spotted by Graphite Agent
Is this helpful? React 👍 or 👎 to let us know.
43ea3d4 to
3a6f591
Compare
feb3c8d to
f49876f
Compare
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
f49876f to
831d0d5
Compare
Description