Skip to content

Commit 8939f6f

Browse files
authored
Fix: Support empty style attribute (#296)
Fixes a bug in which empty style attributes result in unrecoverable JSX failures. For example: ```html <div style>Foo</div> ``` Would result in the following console error: ``` Uncaught Invariant Violation: The `style` prop expects a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + 'em'}} when using JSX. ``` and the React JSX failing to render. The problem is that empty properties are rendered as boolean `true` by default. This is consistent with HTML/React syntax interop expectations for most properties but not `style`, which expects an `Object` value in React-land. Since an empty `style` attribute is semantically meaningless (where HTML is concerned) we can simply skip over this property.
1 parent be04c33 commit 8939f6f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ export function compiler(markdown, options) {
818818
{ key: index }
819819
);
820820
}
821-
} else {
821+
} else if (raw !== 'style') {
822822
map[ATTRIBUTE_TO_JSX_PROP_MAP[raw] || raw] = true;
823823
}
824824

0 commit comments

Comments
 (0)