Skip to content

TSX: Adding space in no-children non-self-closing component can be a build breaking change #764

@Avasam

Description

@Avasam

Describe the bug

dprint-plugin-typescript version: 0.95.13

Non-html-standard components that have no children but are not self-closing are not safe to add newlines/spaces in children

(in fact, even standard html element is probably an incorrect change for a formatter as adding whitespaces technically changes the program's behaviour given it can render differently with the right CSS)

type MyCustomComponentProps = {
  bar: bool
  baz: bool
}
const MyCustomComponent: React.FC<MyCustomComponentProps> = (props) => <>{bar}{baz}</>

Input Code

const foo = () => (
  <MyCustomComponent
    bar
    baz
   ></MyCustomComponent>
)

Expected Output

const foo = () => (
  <MyCustomComponent
    bar
    baz
   ></MyCustomComponent>
)

Actual Output

const foo = () => (
  <MyCustomComponent
    bar
    baz
   >
   </MyCustomComponent>
)
Image
Type '{ children: never[]; className: string; id: string; fetcher: DataEventLogFetcher; }' is not assignable to type 'IntrinsicAttributes & ButtonProps'.
  Property 'children' does not exist on type 'IntrinsicAttributes & ButtonProps'.

Relates to:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions