preactjs / preact

⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
https://preactjs.com
MIT License
36.82k stars 1.95k forks source link

Fragment induced memory leak if not keyed and state change triggered by context #4558

Open glenveegee opened 3 hours ago

glenveegee commented 3 hours ago

Describe the bug When a parent component undergoes state transitions due to context changes, and it returns a fragment which bounds two or more child components that are themselves modified by changes in different parts of the context (so keying the fragment makes no sense), memory will leak and the heap will ultimately fill up and throw an error

To Reproduce

Instructions on how to reproduce and a demonstration of the memory leak are available in the following repo: https://github.com/glenveegee/preact_fragment_memleak

Steps to reproduce the behaviour:

Expected behavior

glenveegee commented 3 hours ago

I should add that running the same code with React has no such memory leak issue with Fragment used in the way it is in the demo repo above (https://github.com/glenveegee/preact_fragment_memleak)

JoviDeCroock commented 3 hours ago

@glenveegee this is probably only present in development and is an issue with prefresh https://github.com/preactjs/prefresh/issues/558 - you can try to disable prefresh in vite to reproduce that