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

"Components keep being added when updating state" issue persists when using tags other than div #4283

Closed
1 task done
yy0931 opened this issue Feb 16, 2024 · 1 comment · Fixed by #4284
Closed
1 task done

Comments

@yy0931
Copy link

yy0931 commented Feb 16, 2024

  • Check if updating to the latest Preact version resolves the issue

Thank you for addressing #4274, but the fix did not resolve the issue in my case. The code snippet I provided had been simplified to use only <div>, but I am actually using different tags. When I change <div></div> before {cond && ... } to <span></span>, the bug still persists.

import { render } from "preact"
import { useEffect, useState } from "preact/hooks"

const B = () => <div>B</div>

const Test = () => {
    const [state, setState] = useState(true)
    useEffect(() => {
        const timer = setInterval(() => {
            setState((s) => !s)
        }, 250)
        return () => { clearInterval(timer) }
    }, [])

    if (state) {
        return <div>
            <B />
            <div></div>
        </div>
    } else {
        const cond = false
        return <div>
            <span></span>
            {cond && <div></div>}
            <B />
            <div></div>
        </div>
    }
}

render(<Test />, document.body)

To Reproduce, copy-paste the above code to https://preactjs.com/repl to see that the text "B" is continuously added. (The site indicates "v10.19.3," but I'm assuming the REPL is using v10.19.5 because the previous bug has been fixed.)

Expected behavior
Only a single instance of <B /> should be shown.

@rschristian
Copy link
Member

FWIW, the banner on the site is purely for showing the latest release (and we have a little infra bug so it's showing the fallback, hardcoded version at the moment) -- it has no connection to the version available in the REPL.

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

Successfully merging a pull request may close this issue.

2 participants