Repository navigation
Description
Could Fabric's attribute configuration expose separate resetValue and defaultValue options? They cover different cases:
defaultValue: the value to send when a prop is omitted orundefinedin a new view's initial props.resetValue: the value to send when a previously provided prop is removed or becomesundefinedduring an update.
The options would accept arbitrary payload values supported by the component's transport, including undefined, null, numeric defaults such as 13.0, opaque objects, or potentially a unique Symbol sentinel on the direct JSI path.
Nitro treats T? as T | undefined, with null available as an explicit value in types such as T | null | undefined. React Native's attribute diff converts explicit undefined to null and sends null for removed props. Native code cannot distinguish removal from explicit null.
This came up in margelo/nitro#2049. Accepting null in Nitro's shared optional converter would change ordinary method calls and erase explicit null values in optional nullable types. Handling it only in the view adapter limits the scope, but still cannot recover the distinction.
A proposed configuration could look like this:
const RESET_PROP = Symbol('nitro.propReset');
const nitroAttribute = {
diff: (previous, next) => previous !== next,
process: value => value,
};
const validAttributes = {
value: {
...nitroAttribute,
defaultValue: 13.0,
resetValue: undefined,
},
optionalValue: {
...nitroAttribute,
defaultValue: undefined,
resetValue: undefined,
},
customValue: {
...nitroAttribute,
resetValue: RESET_PROP,
},
};For the value attribute above:
| Case | Payload |
|---|---|
Initial render with the prop omitted or undefined |
{value: 13} |
| Prop unchanged on a later render | No key |
Previously provided prop omitted or set to undefined |
{value: undefined}, with the key present |
Prop explicitly set to null |
{value: null} |
These options should be independent. Setting defaultValue would not implicitly configure resetValue. With no defaultValue, initial omission would keep today's behavior of sending no value. With no resetValue, removal would keep today's null sentinel. An omitted prop on an update must not reapply defaultValue on every render.
Both options would be final payload values, bypassing process. An explicitly provided value, including null, would follow normal processing. Change detection should use the original props before substituting a reset value, since that value might equal an ordinary prop value.
Configuration must use property-presence checks so {resetValue: undefined} and {defaultValue: undefined} remain distinct from absent options. The payload must also retain a present key whose value is undefined; dropping the key means retaining the previous native value. Nested prop handling would need the same rules.
preserveUndefined: true was the initial suggestion. resetValue: undefined covers that use case and allows other sentinels or concrete values. defaultValue separately covers initial absence. Native defaults through convertRawProp or Nitrogen could continue to be used when no JS-side default is configured.
A Symbol sentinel would let Nitro interpret removal as a reset operation and choose the appropriate native default without conflating it with a supplied null. RN 0.88's JS payload creation and diff preserve Symbol identity for explicitly supplied values, and the JSI raw-props parser stores values directly. Symbol support still needs native integration testing: conversion to folly::dynamic rejects Symbols, so it cannot be assumed for every transport. Nitro would need to recognize the exact sentinel before normal value conversion.
This can be reproduced at the JS diff layer in RN 0.88.0. Add this case to ReactNativeAttributePayload-itest.js, which already imports diff:
it('shows that removal, undefined, and null produce the same payload', () => {
const calls = [];
const validAttributes = {
value: {
diff: (previous, next) => previous !== next,
process: value => {
calls.push(value);
return value;
},
},
};
expect(diff({value: 7}, {}, validAttributes)).toEqual({value: null});
expect(calls).toEqual([]);
expect(
diff({value: 7}, {value: undefined}, validAttributes),
).toEqual({value: null});
expect(calls).toEqual([null]);
calls.length = 0;
expect(diff({value: 7}, {value: null}, validAttributes)).toEqual({
value: null,
});
expect(calls).toEqual([null]);
});A custom process function cannot reliably implement the desired behavior: explicit undefined is normalized before processing, and removal skips processing entirely. Returning undefined from the processor can also be overwritten by the removal pass because payload checks use payload[key] !== undefined.
Relevant code: undefined normalization, removal handling.
Would these two options fit Fabric's attribute configuration?
Activity
react-native-bot commentedon Nov 9, 2026
Warning
Missing reproducer: We could not detect a reproducible example in your issue report. Reproducers are mandatory and we can accept only one of those as a valid reproducer:
You can read more about about it on our website: How to report a bug.
[-]Fabric: allow views to preserve undefined and explicit null in prop updates[/-][+]Fabric: configurable resetValue and defaultValue for native view props[/+]hannojg commentedon Nov 9, 2026
This could also be handy for the props 2.0 diff mechanism where we put/use the default values for props. (Instead of a strings default being
""the developer could already express what the default should be)