docs: clarify editor and recorder internals

This commit is contained in:
hazre committed 2026-03-22 19:18:52 +01:00
1 parent f22a764971
commit e5d52300b5
3 files changed
+11

No files matched your search

+6
View File
@@ -169,6 +169,9 @@ export const CustomEditor = forwardRef<HTMLDivElement, CustomEditorProps>(
const isRenderedSingleLine = !layoutIsMultiline;
if (isRenderedSingleLine && scroll) {
// Scroll.clientWidth is the width the editable actually gets after padding and
// scrollbar math. Cache that delta while we are rendered single-line so later
// hidden measurements can compare against the same usable width.
const renderedSingleLineWidth = scroll.clientWidth;
if (renderedSingleLineWidth > 0) {
singleLineWidthOffsetRef.current = Math.max(
@@ -231,6 +234,9 @@ export const CustomEditor = forwardRef<HTMLDivElement, CustomEditorProps>(
textMeasurer.style.textTransform = computedStyle.textTransform;
textMeasurer.style.textIndent = computedStyle.textIndent;
textMeasurer.style.tabSize = computedStyle.tabSize;
// Measure against a hidden clone instead of the live editable so we can ask
// "would this wrap at single-line width?" without the current layout feeding
// back into the answer.
const measureHeight = (content: string, width: string): number => {
textMeasurer.style.width = width;
textMeasurer.textContent = normalizeMeasurementText(content);
@@ -65,6 +65,8 @@ export const AudioMessageRecorder = forwardRef<
onAudioLengthUpdateRef.current = onAudioLengthUpdate;
const stableOnStop = useCallback((payload: VoiceRecorderStopPayload) => {
// useVoiceRecorder also stops during cancel/teardown paths, so only surface a completed
// recording after an explicit user stop.
if (!userRequestedStopRef.current) return;
if (isDismissedRef.current) return;
onRecordingCompleteRef.current({
@@ -146,11 +146,14 @@ export function useVoiceRecorder(options: UseVoiceRecorderOptions = {}): UseVoic
if (!audioContext) return;
if (recordingStream) {
// Recording contexts are disposable. Closing them fully releases the capture graph so
// mobile browsers do not keep the mic route or low-quality audio mode alive.
if (audioContext.state !== 'closed') {
audioContext.close().catch(() => {});
}
return;
}
// Playback reuses a shared context, so suspend it instead of tearing it down.
if (audioContext.state !== 'closed') {
audioContext.suspend().catch(() => {});
}