Skip to content

Children's key is missing #301

Open
@yoyoyooo

Description

@yoyoyooo

Issue: There is something wrong with children's key.
Example: The expected output should be

<RowItem key="1-1">
    <RadioButton 
        key="1-1-0" 
        checked={false} 
        disabled={false} 
        label="auto" 
        name="1-1" 
        tabIndex="0"
    />
</RowItem>

But I got an output without RadioButton's key:

<RowItem key="1-1">
    <RadioButton 
        checked={false} 
        disabled={false} 
        label="auto" 
        name="1-1" 
        tabIndex="0"
    />
</RowItem>

I am sure the radio button element is correct:

      { '$$typeof': Symbol(react.element),
        type: [Function: RadioButton],
        key: '1-1-0',
        ref: null,
        props: 
         { label: 'auto',
           tabIndex: '0',
           disabled: false,
           checked: false,
           name: '1-1' },
        _owner: null,
        _store: {} }

Any suggestions about this?

Activity

armandabric

armandabric commented on Jul 26, 2018

@armandabric
Collaborator

Hello @yoyoyooo, did you have a more complete example to show us?

I just check our test suite, we have use case with some key usage:

it('reactElementToJSXString(<div aprop="test" key="yes" />', () => {
expect(reactElementToJSXString(<div aprop="test" key="yes" />)).toEqual(
`<div
key="yes"
aprop="test"
/>`

yoyoyooo

yoyoyooo commented on Jul 26, 2018

@yoyoyooo
Author

I think this test case is not suitable to my problem because there is only one div. My problem is if both child and parent have its key attribute, the child's key cannot been shown. I can give another example based on your test case.

Input

reactElementToJSXString(
	<div aprop="test" key="yes">
		<div aprop="test" key="yes" />
	</div>
)

Output

<div
  key="yes"
  aprop="test"
>
  <div aprop="test" />
</div>

The inner div's key is missing.

DanielHara

DanielHara commented on Jan 30, 2024

@DanielHara

Looks like this issue is still happening in version 15.0.0:

Input:

import React from "https://esm.sh/react@18.2.0";
import reactElementToJsxString from "https://esm.sh/react-element-to-jsx-string@15.0.0";

console.log(reactElementToJsxString(
	<div aprop="test" key="yes">
		<div aprop="test" key="yes" />
	</div>
));

Output:

"<div
  key='yes'
  aprop='test'
>
  <div aprop='test' />
</div>"

To reproduce: https://codepen.io/danielhara/pen/GReQOPX?editors=1111

linked a pull request that will close this issue on Jan 30, 2024
DanielHara

DanielHara commented on Jan 30, 2024

@DanielHara

@armandabric , @yoyoyooo , I've created this PR to fix this bug: #841 🚀

added 3 commits that reference this issue on Jan 30, 2024
7876b72
ce3796c
bb921d1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @armandabric@yoyoyooo@DanielHara

      Issue actions

        Children's key is missing · Issue #301 · algolia/react-element-to-jsx-string