Skip to content

Conversation

canac
Copy link
Contributor

@canac canac commented Aug 25, 2025

Description

Create the saving indicator area to show the user while a mutation is in progress and subtly indicate that their changes are automatically saved.

Any new goal calculator mutations will also need to call onMutationStart and onMutationComplete.

MPDX-8708

Checklist:

  • I have given my PR a title with the format "MPDX-(JIRA#) (summary sentence max 80 chars)"
  • I have applied the appropriate labels. (Add the label "On Staging" to get the branch automatically merged into staging.)
  • I have requested a review from another person on the project

@canac canac requested a review from dr-bizz August 25, 2025 22:09
@canac canac self-assigned this Aug 25, 2025
@canac canac added the Preview Environment Add this label to create an Amplify Preview label Aug 25, 2025
Copy link
Contributor

Preview branch generated at https://8708-saving-indicator.d3dytjb8adxkk5.amplifyapp.com

// Rerender periodically to update the saved at time
const [_tick, setTick] = useState(0);
useEffect(() => {
const interval = setInterval(() => setTick((tick) => tick + 1), 5000);
Copy link
Contributor

Choose a reason for hiding this comment

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

[Must-fix] Memory leak potential: interval not cleared on unmount in strict mode. Evidence: setInterval without ref storage. Impact: Multiple intervals in development. Fix: Store interval ref. [Category: File]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm confused by this suggestion. In strict mode, won't the useEffect run twice? So it will start the interval, stop the interval on unmount, and then remount and start the interval again? Then when the component is unmounted, it will stop the interval again. I might be missing something, but also ChatGPT says this code cleans up correctly and doesn't leak the interval.

Comment on lines +23 to +26
useEffect(() => {
const interval = setInterval(() => setTick((tick) => tick + 1), 5000);
return () => clearInterval(interval);
}, []);
Copy link
Contributor

Choose a reason for hiding this comment

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

[Reuse] Interval pattern could use custom useInterval hook. Evidence: Manual setInterval/clearInterval. Impact: Reusability and cleanup. Suggestion: Create shared useInterval hook. [Category: Reuse]

// Rerender periodically to update the saved at time
const [_tick, setTick] = useState(0);
useEffect(() => {
const interval = setInterval(() => setTick((tick) => tick + 1), 5000);
Copy link
Contributor

Choose a reason for hiding this comment

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

[Suggested tests] Test interval cleanup on unmount and re-render timing. Evidence: setInterval usage. Impact: Memory leak prevention. Test periodic formatRelativeTime updates. [Category: File]

@canac canac force-pushed the 8760-api-categories branch 2 times, most recently from b55a548 to aafadcc Compare August 28, 2025 18:48
Base automatically changed from 8760-api-categories to main August 28, 2025 18:59
@canac canac force-pushed the 8708-saving-indicator branch from e51ebea to c2dd0f0 Compare September 11, 2025 21:15
Copy link
Contributor

Bundle sizes [mpdx-react]

Compared against 0cd5682

No significant changes found

@canac canac enabled auto-merge September 11, 2025 21:44
@canac canac merged commit 7ddc71f into main Sep 11, 2025
27 of 31 checks passed
@canac canac deleted the 8708-saving-indicator branch September 11, 2025 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Preview Environment Add this label to create an Amplify Preview
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants