Skip to content

Conversation

@garrity-miepub
Copy link
Contributor

Move stopRecording callback definition before startRecording to fix 'Cannot access stopRecording before initialization' ReferenceError.

The issue occurred because startRecording referenced stopRecording in both its function body (for maxDuration auto-stop) and its dependency array, but stopRecording was defined after startRecording. JavaScript's temporal dead zone prevents accessing const/let variables before their declaration, even within useCallback closures.

This bug prevented the Dashboard example page and any component using RecordButton from rendering in Storybook.

image

Move stopRecording callback definition before startRecording to fix
'Cannot access stopRecording before initialization' ReferenceError.

The issue occurred because startRecording referenced stopRecording in
both its function body (for maxDuration auto-stop) and its dependency
array, but stopRecording was defined after startRecording. JavaScript's
temporal dead zone prevents accessing const/let variables before their
declaration, even within useCallback closures.

This bug prevented the Dashboard example page and any component using
RecordButton from rendering in Storybook.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a runtime ReferenceError (temporal dead zone) that prevented RecordButton (and the Dashboard Storybook example) from rendering by reordering hook callback definitions.

Changes:

  • Moves stopRecording’s useCallback definition above startRecording so it can be safely referenced in startRecording’s body and dependency array.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +264 to +279
const stopRecording = React.useCallback(() => {
if (timerRef.current) {
clearInterval(timerRef.current);
}

if (
mediaRecorderRef.current &&
mediaRecorderRef.current.state !== 'inactive'
) {
mediaRecorderRef.current.stop();
}

if (streamRef.current) {
streamRef.current.getTracks().forEach((track) => track.stop());
}
}, []);
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

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

Consider adding/expanding a Playwright Storybook render/visual test that covers the Dashboard story (or a RecordButton story) to prevent regressions where RecordButton fails to render due to hook callback ordering/initialization errors (this bug was only caught at runtime in Storybook).

Copilot uses AI. Check for mistakes.
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