I see it now! The getValues function has this logic:
let values = {
...(_state.mount ? _formValues : _defaultValues),
};
So when _state.mount is true, it returns _formValues, which is {} when shouldUnregister is true. But when _state.mount is false, it returns _defaultValues.
So the issue is that after the first render (when _state.mount becomes true), getValues() returns _formValues which is {} when shouldUnregister is true.
But wait, the handleSubmit function also uses _formValues:
let fieldValues:
| TFieldValues
| TTransformedValues
| Record<string, never> = cloneObject(_formValues);
So the same issue applies here. When shouldUnregister is true and the form is submitted, fieldValues is {}.
Now, the question is: what's the expected behavior? When shouldUnregister is true, fields that are unmounted are unregistered (removed from the form state). But when values is provided via props.values, those values should still be available.
Let me think about this more carefully. The values prop is used to provide initial values to the form. When fields are registered, they should get their values from the DOM (or from defaultValue/value props). The shouldUnregister option is for unregistering fields when they are unmounted.
But when values is provided, the form should use those values as the initial form values, even when shouldUnregister is true.
OK so I think the issue is that when shouldUnregister is true and values is provided, the _reset function sets _formValues to {} instead of the values from props.values. This is wrong because the values prop should still be used as the initial form values.
Looking at the _reset function:
_formValues = _options.shouldUnregister
? keepStateOptions.keepDefaultValues
? (cloneObject(_defaultValues) as TFieldValues)
: ({} as TFieldValues)
: (cloneObject(values) as TFieldValues);
When shouldUnregister is true and keepDefaultValues is false, _formValues is set to {}. But this is incorrect when values is provided via props.values.
Wait, but the _reset function is called with keepFieldsRef: true when the values effect runs:
control._reset(props.values, {
keepFieldsRef: true,
...control._options.resetOptions,
});
The keepFieldsRef option doesn't affect the _formValues setting. It only affects whether we iterate over mounted fields and call setValue for each.
I think the fix should be to also set _formValues when values is provided, even when shouldUnregister is true.
Actually, wait. Let me think about the expected behavior more carefully:
-
When shouldUnregister is true and values is provided:
- Initial form values should be the
values prop
- When fields are registered, they get their values from the DOM
- When fields are unmounted, they are unregistered (removed from form state)
- When the form is submitted, the form values should be collected from registered fields
-
The values prop is similar to defaultValues, but it allows the form values to be updated from outside.
So the issue is that when shouldUnregister is true, _formValues is set to {} after the reset, and getValues() returns {}.
But wait, I think there's a distinction between:
- Form values collected from registered fields (which is what
getValues() should return)
- Initial/default values provided via props (which are used to initialize the form)
When shouldUnregister is true, the form values are expected to come from the DOM (registered fields), not from _formValues. So when there are no registered fields, getValues() returns {}.
But when values is provided, those values should be available even when there are no registered fields.
Hmm, actually, I think the fix should be in the values effect. When props.values changes, we should update _formValues to include the new values, even when shouldUnregister is true.
Actually wait, let me re-read the _reset function again:
if (!keepStateOptions.keepValues) {
...
_formValues = _options.shouldUnregister
? keepStateOptions.keepDefaultValues
? (cloneObject(_defaultValues) as TFieldValues)
: ({} as TFieldValues)
: (cloneObject(values) as TFieldValues);
...
}
So when shouldUnregister is true and keepDefaultValues is false, _formValues is set to {}. But the values are emitted via:
_subjects.state.next({
values: { ...values } as TFieldValues,
});
So the form state subscribers receive the correct values. But getValues() returns _formValues when _state.mount is true.
Actually, I think the issue is that getValues() should return _defaultValues when shouldUnregister is true and _state.mount is true and there are no registered fields.
But wait, _getWatch also has a similar issue. Let me check:
React.useEffect(() => {
props.shouldUnregister &&
control._subjects.state.next({
values: control._getWatch(),
});
}, [control, props.shouldUnregister]);
This effect runs when shouldUnregister changes. But control is stable (ref.current), so this effect runs on mount and whenever shouldUnregister changes.
On mount, _getWatch() returns {} because _formValues is {}.
Actually, wait. Let me trace through the code more carefully.
When useForm is called with props.values and props.shouldUnregister:
-
createFormControl is called with props
-
In createFormControl:
_defaultValues is set to cloneObject(props.values) (because props.values is an object)
_formValues is set to {} (because shouldUnregister is true)
_state.mount is false
-
In useForm:
- The
shouldUnregister effect runs (on mount)
_getWatch() is called
_getWatch() calls generateWatchOutput(_fields, _names, _formValues, _proxyFormState, _defaultValues)
generateWatchOutput returns _formValues which is {}
_subjects.state.next({ values: {} }) is called
Wait, but actually, _getWatch is defined as:
const _getWatch: WatchInternal<TFieldValues> = (
fieldName,
watchAll,
defaultValues,
) => {
if (isUndefined(fieldName)) {
if (!watchAll && names.watchAll) {
return cloneObject(_formValues) as TFieldValues;
}
...
return generateWatchOutput(
_fields,
_names,
_formValues,
_proxyFormState,
isUndefined(defaultValues) ? _defaultValues : defaultValues,
);
}
};
And generateWatchOutput is:
export default <T>(
names: string | string[] | undefined,
_names: Names,
formValues?: FieldValues,
isGlobal?: boolean,
defaultValue?: DeepPartial<T> | unknown,
) => {
if (isString(names)) {
isGlobal && _names.watch.add(names);
return get(formValues, names, defaultValue);
}
if (Array.isArray(names)) {
return names.map(
(fieldName) => (
isGlobal && _names.watch.add(fieldName),
get(formValues, fieldName)
),
);
}
isGlobal && (_names.watchAll = true);
return formValues;
};
So when _getWatch() is called without arguments, generateWatchOutput is called with undefined for names, which falls through to return formValues, which is _formValues, which is {}.
So _getWatch() returns {}, and the shouldUnregister effect emits { values: {} }.
-
So after step 5, the form state subscribers should have the correct values from step 5. But the shouldUnregister effect already emitted { values: {} } in step 3.
Wait, but React batches effects. Let me think about the order of execution...
Actually, effects in React run sequentially, one after the other. So:
- First effect (shouldUnregister) runs and emits
{ values: {} }
- Second effect (values) runs and emits
{ values: { ...values } }
So the subscribers should receive { values: {} } first, then { values: { ...values } }. The final state should have the correct values.
But wait, the issue says "values data is reset after first render". This means the values ARE correct on first render, but become empty after.
Let me re-read the useEffect:
React.useEffect(() => {
if (props.values && !deepEqual(props.values, _values.current)) {
control._reset(props.values, {
keepFieldsRef: true,
...control._options.resetOptions,
});
if (!control._options.resetOptions?.keepIsValid) {
control._setValid();
}
_values.current = props.values;
updateFormState((state) => ({ ...state }));
} else {
control._resetDefaultValues();
}
}, [control, props.values]);
On the first render:
props.values is the values object (e.g., { name: 'test' })
_values.current is undefined
!deepEqual(props.values, _values.current) is true (comparing an object to undefined)
- We enter the
if branch and call _reset(props.values, ...)
_values.current is set to props.values
updateFormState((state) => ({ ...state })) is called
But wait, the shouldUnregister effect is defined BEFORE the values effect. And both depend on control, which is stable. So both effects run on mount.
Actually, I need to check the effect execution order more carefully. In React, effects run in the order they are defined. So:
shouldUnregister effect runs first
values effect runs second
But within each effect, the code runs synchronously. So the shouldUnregister effect calls _subjects.state.next({ values: {} }), which triggers subscribers to update. Then the values effect calls _reset(props.values, ...), which also calls _subjects.state.next({ values: { ...values } }), triggering subscribers to update again.
So subscribers receive { values: {} } first, then { values: { ...values } }. The final state should have the correct values.
Hmm, but the issue says values are reset after first render. Let me think about what happens during re-renders.
On a re-render (e.g., when the parent component re-renders and passes new props):
- If
props.values is the same reference, !deepEqual(props.values, _values.current) is false
- We enter the
else branch and call control._resetDefaultValues()
Wait, that's the issue! On a re-render where props.values hasn't changed, we enter the else branch and call control._resetDefaultValues().
Let me look at _resetDefaultValues:
const _resetDefaultValues = () =>
isFunction(_options.defaultValues) &&
(_options.defaultValues as Function)().then((values: TFieldValues) => {
reset(values, _options.resetOptions);
_subjects.state.next({
isLoading: false,
});
});
So _resetDefaultValues() only does something if _options.defaultValues is a function. If it's not a function, _resetDefaultValues() returns immediately without doing anything.
OK so on a re-render where props.values hasn't changed and props.defaultValues is not a function, nothing happens.
But wait, there's another issue. The shouldUnregister effect runs on mount and on every re-render where shouldUnregister or control changes. But control is stable, so the effect only runs on mount and when shouldUnregister changes.
Actually, wait. Let me re-check the dependencies of the shouldUnregister effect:
React.useEffect(() => {
props.shouldUnregister &&
control._subjects.state.next({
values: control._getWatch(),
});
}, [control, props.shouldUnregister]);
The dependencies are [control, props.shouldUnregister]. Since control is stable (ref.current doesn't change), this effect only runs when props.shouldUnregister changes. On the first render, props.shouldUnregister is true, so the effect runs.
But wait, I also see this effect in the useForm.ts file:
useIsomorphicLayoutEffect(() => {
const sub = control._subscribe({
formState: control._proxyFormState,
callback: () =>
updateFormState({
...control._formState,
defaultValues:
control._defaultValues as FormState<TFieldValues>['defaultValues'],
}),
reRenderRoot: true,
});
updateFormState((data) => ({
...data,
isReady: true,
}));
control._formState.isReady = true;
return sub;
}, [control]);
This is a useIsomorphicLayoutEffect that subscribes to the form state. And it depends on control, which is stable. So this effect runs on mount.
Hmm, let me think about this more carefully. The issue is that when shouldUnregister is true, the _formValues is {}. And getValues() returns _formValues when _state.mount is true.
But actually, looking at the handleSubmit function:
let fieldValues:
| TFieldValues
| TTransformedValues
| Record<string, never> = cloneObject(_formValues);
This is where the issue is. When shouldUnregister is true and the form is submitted, fieldValues is {}.
But the user expects that the values from props.values should be submitted, not {}.
I think the fix should be to ensure that _formValues contains the values from props.values when shouldUnregister is true, or at least merge _formValues with _defaultValues in handleSubmit.
Actually, wait. Let me look at the _reset function more carefully:
if (!keepStateOptions.keepValues) {
...
_formValues = _options.shouldUnregister
? keepStateOptions.keepDefaultValues
? (cloneObject(_defaultValues) as TFieldValues)
: ({} as TFieldValues)
: (cloneObject(values) as TFieldValues);
...
}
When shouldUnregister is true and keepDefaultValues is false, _formValues is set to {}. But the values are emitted via _subjects.state.next({ values: { ...values } }).
The issue is that _subjects.state.next({ values: { ...values } }) triggers form state updates, but getValues() and handleSubmit use _formValues directly, which is {}.
I think the fix should be to set _formValues to {...values} when props.values is provided, even when shouldUnregister is true. But we also need to ensure that when fields are registered/unregistered, the _formValues is updated correctly.
Actually, let me look at how _formValues is updated when fields are registered:
const register: UseFormRegister<TFieldValues> = (
name,
options,
) => {
...
if (!._mount) {
...
_formValues[name] = getFieldValue(fieldReference);
...
}
...
};
So when a field is registered, its value is read from the DOM and stored in _formValues. This is correct for shouldUnregister: true, because the values should come from the DOM.
But when props.values is provided, the initial values should come from props.values, not from the DOM.
I think the issue is that when shouldUnregister is true and values is provided:
- The
_reset function sets _formValues to {} and emits the values via _subjects.state.next({ values: { ...values } })
- The
shouldUnregister effect calls _getWatch() which returns {} because _formValues is {}
- The
shouldUnregister effect emits { values: {} }
So the form state subscribers receive { values: {} } from the shouldUnregister effect, overwriting the correct values that were emitted by the _reset function.
Wait, but the _reset function emits the values AFTER the shouldUnregister effect runs (because _reset is called in the values effect, which runs after the shouldUnregister effect). So the final state should have the correct values.
Unless... the shouldUnregister effect runs AGAIN after the values effect.
Let me re-check. On the first render:
shouldUnregister effect runs
props.shouldUnregister is true
_getWatch() returns {} because _formValues is {}
_subjects.state.next({ values: {} }) is called
values effect runs
_reset(props.values, ...) is called
_subjects.state.next({ values: { ...values } }) is called
So the order is: { values: {} } first, then { values: { ...values } }. The subscribers should have the correct final values.
But wait, there's another effect that might be involved:
useIsomorphicLayoutEffect(() => {
const sub = control._subscribe({
formState: control._proxyFormState,
callback: () =>
updateFormState({
...control._formState,
defaultValues:
control._defaultValues as FormState<TFieldValues>['defaultValues'],
}),
reRenderRoot: true,
});
...
}, [control]);
This is a useIsomorphicLayoutEffect (similar to useLayoutEffect), which runs synchronously after all DOM mutations but before the useEffect hooks. So the order is:
useIsomorphicLayoutEffect runs and subscribes to the form state
useEffect for shouldUnregister runs and emits { values: {} }
useEffect for values runs and calls _reset, which emits { values: { ...values } }
So the subscriber receives { values: {} } first, then { values: { ...values } }. The final state should have the correct values.
Hmm, but the issue says values are reset after first render. Let me think about this differently.
Actually, maybe the issue is that the shouldUnregister effect runs AGAIN after the values effect, because the values effect changes something that causes the shouldUnregister effect to re-run.
Wait, but the shouldUnregister effect depends on [control, props.shouldUnregister]. Neither of these change when the values effect runs. So the shouldUnregister effect shouldn't re-run.
Unless... the values effect calls updateFormState, which triggers a re-render, which causes the shouldUnregister effect to re-run.
Actually, let me look at the values effect again:
React.useEffect(() => {
if (props.values && !deepEqual(props.values, _values.current)) {
control._reset(props.values, {
keepFieldsRef: true,
...control._options.resetOptions,
});
if (!control._options.resetOptions?.keepIsValid) {
control._setValid();
}
_values.current = props.values;
updateFormState((state) => ({ ...state }));
} else {
control._resetDefaultValues();
}
}, [control, props.values]);
After calling _reset(props.values, ...), the effect also calls updateFormState((state) => ({ ...state })). This might trigger a re-render.
If a re-render happens, and props.shouldUnregister is still true, the shouldUnregister effect will run again. On re-render:
control is still the same reference
props.shouldUnregister is still true
- So the effect runs again (because the dependencies haven't changed? No wait, React doesn't re-run effects if the dependencies haven't changed)
Actually, React only re-runs effects if the dependencies have changed. If control and props.shouldUnregister haven't changed, the effect won't re-run.
OK let me re-read the issue description:
"Simply submit a form
See error"
So the issue is about form submission. Let me re-check the handleSubmit function:
const handleSubmit: UseFormHandleSubmit<TFieldValues, TTransformedValues> =
(onValid, onInvalid) => async (e) => {
...
let fieldValues:
| TFieldValues
| TTransformedValues
| Record<string, never> = cloneObject(_formValues);
...
So when the form is submitted, fieldValues is initialized to cloneObject(_formValues), which is {} when shouldUnregister is true.
This is the issue! Even if the form state has the correct values (from the _reset function), handleSubmit uses _formValues directly, which is {} when shouldUnregister is true.
So the fix should be in handleSubmit to ensure that _formValues is updated when props.values is provided.
Actually, I think the fix should be in _reset. When props.values is provided and shouldUnregister is true, _formValues should be set to {...values} instead of {}.
But wait, that would defeat the purpose of shouldUnregister, which is to not store field values in _formValues.
Hmm, let me think about this more carefully. The purpose of shouldUnregister is to remove field values when fields are unmounted. But the initial values should still be available.
Actually, I think the issue is that _formValues should be set to the values from props.values initially, even when shouldUnregister is true. The _formValues is used to store the current form values, and when shouldUnregister is true, it should be emptied when fields are unmounted. But initially, it should have the values from props.values.
Wait, but when fields are registered, their values are read from the DOM and stored in _formValues. So if props.values has different values than the DOM, _formValues will be updated with the DOM values when fields are registered.
So the question is: what should _formValues be set to initially when shouldUnregister is true and props.values is provided?
I think the answer is that _formValues should be set to {...values} (the values from props.values) initially. When fields are registered, their values from the DOM will overwrite the values in _formValues. When fields are unmounted, their values will be removed from _formValues.
But the current code sets _formValues to {} when shouldUnregister is true and keepDefaultValues is false. This is incorrect because it doesn't preserve the initial values from props.values.
Let me look at the _reset code again:
if (!keepStateOptions.keepValues) {
...
_formValues = _options.shouldUnregister
? keepStateOptions.keepDefaultValues
? (cloneObject(_defaultValues) as TFieldValues)
: ({} as TFieldValues)
: (cloneObject(values) as TFieldValues);
...
}
When shouldUnregister is true:
- If
keepDefaultValues is true, _formValues is set to cloneObject(_defaultValues)
- Otherwise,
_formValues is set to {}
The issue is that when shouldUnregister is true, _formValues is set to {} even when values is provided via props.values. The fix should be to set _formValues to {...values} when values is provided.
Wait, but actually, _defaultValues is set to the values from props.values:
if (!keepStateOptions.keepDefaultValues) {
_defaultValues = updatedValues;
}
So _defaultValues contains the correct values. And getValues() returns _defaultValues when _state.mount is false:
let values = {
...(_state.mount ? _formValues : _defaultValues),
};
So the issue might be that _state.mount is true when it shouldn't be, or that _state.mount is false initially and then becomes true after the form is rendered.
Let me check how _state.mount is set in _reset:
_state.mount =
!_proxyFormState.isValid ||
!!keepStateOptions.keepIsValid ||
!!keepStateOptions.keepDirtyValues ||
(!_options.shouldUnregister && !isEmptyObject(values));
When shouldUnregister is true and values is not empty:
!_proxyFormState.isValid is true (assuming isValid is not set, which is false initially)
- So
_state.mount is true
So even before the form is rendered, _state.mount is true when shouldUnregister is true. This means getValues() returns _formValues (which is {}) instead of _defaultValues.
Hmm, but actually, _proxyFormState.isValid is false initially (it's part of defaultProxyFormState). So !_proxyFormState.isValid is true, and _state.mount is true.
Wait, but the issue says "values data is reset after first render". This means the values ARE correct initially, but become empty after the first render.
Let me think about the render lifecycle:
-
First render:
_state.mount is false (set in createFormControl)
getValues() returns _defaultValues (because _state.mount is false)
_defaultValues contains the values from props.values
- So
getValues() returns the correct values
-
After first render (when the form is submitted):
_state.mount is true (set in useForm's useEffect)
getValues() returns _formValues (because _state.mount is true)
_formValues is {} (because shouldUnregister is true)
- So
getValues() returns {}
This is the issue! When _state.mount is true, getValues() returns _formValues which is {} when shouldUnregister is true.
OK so the fix should be to ensure that _formValues is set to the values from props.values when shouldUnregister is true and values is provided.
Actually, let me re-read the _reset code:
if (!keepStateOptions.keepValues) {
...
_formValues = _options.shouldUnregister
? keepStateOptions.keepDefaultValues
? (cloneObject(_defaultValues) as TFieldValues)
: ({} as TFieldValues)
: (cloneObject(values) as TFieldValues);
...
}
When shouldUnregister is true and keepStateOptions.keepDefaultValues is false, _formValues is set to {}. But I think the fix should be to set _formValues to {...values} when values is provided.
Actually wait, I think the issue is in the condition. When shouldUnregister is true, the code assumes that field values should come from the DOM, not from _formValues. But when props.values is provided, the initial values should come from props.values.
I think the fix should be:
_formValues = _options.shouldUnregister
? keepStateOptions.keepDefaultValues
? (cloneObject(_defaultValues) as TFieldValues)
: (cloneObject(values) as TFieldValues) // Changed from ({} as TFieldValues)
: (cloneObject(values) as TFieldValues);
Wait, but this would mean that _formValues always contains the values, which defeats the purpose of shouldUnregister.
Actually, I think the purpose of shouldUnregister is to unregister fields when they are unmounted, not to empty _formValues. The values should still be stored in _formValues initially.
But wait, the comment in the code says:
let _formValues = _options.shouldUnregister
? ({} as TFieldValues)
: (cloneObject(_defaultValues) as TFieldValues);
So when shouldUnregister is true, _formValues is initialized to {}. This is because the values should come from the DOM when fields are registered, not from _formValues.
But when props.values is provided, the initial values should come from props.values, not from the DOM. So the fix should be to set _formValues to {...values} when values is provided.
Let me think about this more carefully. The flow is:
useForm is called with props.values and props.shouldUnregister
createFormControl is called
_defaultValues is set to cloneObject(props.values) (because props.values is an object)
_formValues is set to {} (because shouldUnregister is true)
- The
values effect in useForm calls _reset(props.values, { keepFieldsRef: true, ... })
- In
_reset:
_defaultValues is updated to cloneObject(props.values) (because keepDefaultValues is false)
_formValues is set to {} (because shouldUnregister is true and keepDefaultValues is false)
_subjects.state.next({ values: { ...values } }) is called
So the _reset function emits the correct values via _subjects.state.next({ values: { ...values } }). But getValues() returns _formValues which is {}.
Actually, wait. Let me check if the values emitted by _subjects.state.next({ values: { ...values } }) is received by the form state subscribers and used by getValues().
No, getValues() uses _formValues directly, not the values from the subscribers. So even if the subscribers receive the correct values, getValues() returns {}.
So the fix should be to ensure that _formValues is set to the values from props.values when shouldUnregister is true and values is provided.
Actually, let me look at the code flow more carefully. In the values effect:
React.useEffect(() => {
if (props.values && !deepEqual(props.values, _values.current)) {
control._reset(props.values, {
keepFieldsRef: true,
...control._options.resetOptions,
});
...
}
}, [control, props.values]);
The _reset is called with keepFieldsRef: true. But keepFieldsRef doesn't affect how _formValues is set.
Actually, I wonder if the issue is that the values effect doesn't call _reset correctly. Let me re-read the code.
Wait, I think I've been overcomplicating this. Let me re-read the issue:
"values data is reset after first render, when shouldUnregister is provided"
And the reproduction:
- Simply submit a form
- See error
So the issue is that when the form is submitted, the values are {} instead of the values from props.values.
OK so the fix should be in _reset. When shouldUnregister is true and values is provided, _formValues should be set to {...values} instead of {}.
Wait, but actually, I think the issue is different. Let me re-read the _reset code:
if (!keepStateOptions.keepValues) {
...
_formValues = _options.shouldUnregister
? keepStateOptions.keepDefaultValues
? (cloneObject(_defaultValues) as TFieldValues)
: ({} as TFieldValues)
: (cloneObject(values) as TFieldValues);
_subjects.array.next({
values: { ...values },
});
_subjects.state.next({
values: { ...values } as TFieldValues,
});
}
When shouldUnregister is true, _formValues is set to {}, but _subjects.state.next({ values: { ...values } }) emits the correct values.
So the fix should be to also update _formValues when shouldUnregister is true and values is provided.
Actually wait, I think I need to understand the purpose of shouldUnregister better. When shouldUnregister is true:
- Fields are unregistered when they are unmounted
- The values of unregistered fields should be removed from the form state
But the initial values should still be available. So when shouldUnregister is true, _formValues should be initialized to the values from props.values, and updated when fields are registered/unregistered.
I think the fix should be to change the condition in _reset:
_formValues = _options.shouldUnregister
? keepStateOptions.keepDefaultValues
? (cloneObject(_defaultValues) as TFieldValues)
: (cloneObject(values) as TFieldValues) // Changed from ({} as TFieldValues)
: (cloneObject(values) as TFieldValues);
But wait, this would mean that _formValues always contains the values, even when shouldUnregister is true. This might not be the desired behavior.
Actually, I think the current behavior is intentional. When shouldUnregister is true, _formValues is emptied because the values should come from the DOM when fields are registered. But when props.values is provided, the initial values should come from props.values.
Hmm, let me look at this from a different angle. The props.values prop is used to provide values to the form. When shouldUnregister is true, the form should still use these values initially, but update them when fields are registered/unregistered.
I think the fix should be to set _formValues to {...values} when props.values is provided, regardless of shouldUnregister. The shouldUnregister option only affects whether fields are unregistered when they are unmounted, not whether the initial values are preserved.
Actually wait, I see now that there's a subtle difference between defaultValues and values. Let me check the types:
<tool_call>
<function=bash_terminal>
<parameter=command>
grep -A5 "UseFormProps" /react-hook-form/src/types/methods.ts 2>/dev/null || grep -A5 "UseFormProps" /react-hook-form/src/types/*.ts | head -50
</tool_call>