Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSX children duplicated during Typist animation sequence (Error: encountered two children with the same key 'Typist-element-br-.......') #57

Closed
colemahatmccreary opened this issue Aug 24, 2018 · 5 comments

Comments

@colemahatmccreary
Copy link

colemahatmccreary commented Aug 24, 2018

Hi,
I'm working with a typist component that uses dynamically api-generated text as the "child" or nested content.

The Typist component itself is rendered conditionally upon all of the necessary text being loaded to local state and passed into the nested text.

{ this.state.display ? 
        <Typist>
                this is some text. today is {this.state.dayOfWeek}. 
                <br />
                <br />
                it is {this.state.localTemp} degrees outside
                <br />
                <br />
                .....
                <br />
                <br />
                ....
        </Typist>
: '' }

As you can see use a number of <br /> components in the body of this text, and on 80% of page loads, the animation proceeds to the end, but i receive the following error at varying points in the typing sequence:

Warning: Encountered two children with the same key, Typist-element-br-1535132419832.6477. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.
in div (created by Typist)

At the same time as the error message logs in the console, an additional <br /> renders somewhere in the block of text as it continues typing.

this causes the entire block of text to jump down a line (or lines, depending on the number of times this error is thrown).

Any insight on how to avoid this? I've tried explicitly passing a key as a prop/attr on each <br /> but no luck.

Thanks

@cryptoads
Copy link
Contributor

cryptoads commented Aug 26, 2018

I am having the same exact issue.

I ended up breaking my huge Typist component into many smaller components for now and that seemed to fix my issue.

I think I see the issue in the utils.js file and might try submit a fix if I get it figured out.

@jstejada
Copy link
Owner

ahh yeah, it seems to be an issue with computing the key for the elements. happy to take a PR with a fix!

@cryptoads
Copy link
Contributor

PR with fix submitted.

@stevemao
Copy link

#58 should fix it

@jstejada
Copy link
Owner

jstejada commented Jan 2, 2019

closing as #58 has been merged in

@jstejada jstejada closed this as completed Jan 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants