Renaming exported components and props
DevLink now renames exported components and props to ensure that the generated React code has valid, collision-free identifiers. Here is a summary of the changes that it makes:
Components
DevLink sanitizes exported component names to handle:
- Emojis and special characters:
My π ComponentβMyComponent - Numbers at the start:
123βUnknownComponent123,1ComponentβUnknownComponent1Component - Reserved words:
classβUnknownComponentClass - Empty or whitespace-only names:
""or" "βUnknownComponent - Collisions: Multiple components named
MyComponentβMyComponent,MyComponent2,MyComponent3
Props
DevLink sanitizes exported prop names to handle:
- Emojis and special characters:
πβunknownProp - Numbers at the start:
123βunknownProp123,1propβunknownProp1Prop - Reserved words:
returnβreturnProp,privateβprivateProp - React reserved props:
keyβkeyProp,refβrefProp - HTML attributes for component props:
classβclassProp,forβforProp - Empty or whitespace-only names:
""or" "βunknownProp
Note: HTML attributes like data-* and aria-* are preserved as-is and not sanitized.
Whatβs Fixed
This update fixes several critical issues in the previous system:
- No more leading underscores: Previously, names starting with numbers like
123would become_123or__123, which violates JavaScript naming conventions - Better handling of reserved words: Component props named
classorfornow becomeclassPropandforPropinstead of_classand_for - React conflicts resolved: Props named
keyorrefnow becomekeyPropandrefPropto avoid conflicts with Reactβs special props - Fallback for invalid names: Empty or whitespace-only names now get meaningful fallback names instead of breaking
For more information, see What DevLink Exports.