--- name: safe-element-comparison description: Maintain element type comparison safety in remix-forms. Use when modifying component mappings, adding new components to mapChildren, investigating unexpected HTML attributes or prop injection, writing docs about component customization, or responding to user issues about wrong elements receiving props. metadata: internal: true --- # Safe Element Comparison remix-forms identifies components in JSX trees using `child.type === Component`. This pattern is central to how `mapChildren` injects props into the right elements. This skill covers the architecture, the rules for keeping it safe, and guidance for users. ## How It Works `mapChildren` in `children-traversal.ts` recursively walks the React element tree returned by user render functions. Callback functions in `create-field.tsx` and `schema-form.tsx` compare `child.type` against component references to decide which props to inject. React element types follow these rules: - `
` compiles to `React.createElement('div')` — type is the **string** `'div'` - `` compiles to `React.createElement(MyComponent)` — type is the **function/object reference** - `React.forwardRef(fn)` returns a unique object — `===` comparison works reliably when defined at module scope - `React.cloneElement` preserves `.type` exactly - React Fast Refresh preserves component identity in development If a component reference were a string like `'div'`, then `child.type === Component` would match every `
` in the tree — not just the intended component. This is why all default components are `React.forwardRef` wrappers with unique object identity. ## Current Architecture All default components are defined at module scope as `React.forwardRef` wrappers. Each renders its corresponding HTML element and nothing else. Components that render the same HTML tag (e.g. `DefaultInput`, `DefaultCheckbox`, `DefaultRadio` all render ``) are separate objects with distinct identities. ### create-field.tsx | Default wrapper | Renders | Used as default for | |---|---|---| | `DefaultField` | `
` | `fieldComponent` | | `DefaultLabel` | `