Repository navigation
Fix/formkit memory leak - #242
filiphazardous wants to merge 8 commits into
Conversation
|
@filiphazardous is attempting to deploy a commit to the Formkit Team on Vercel. A member of the Team first needs to authorize it. |
justin-schroeder
left a comment
There was a problem hiding this comment.
Thanks for this, and for the test 🙏 — the polling-timer cleanup is exactly right. A few things before it can land:
destroy()becomes a no-op mid-animation —if (animations.has(el) && ... !== 'finished') returnmeans unmounting a component while its parent animates leaves every observer/interval in place (the leak comes right back). Please always tear down; cancel/finish the running animation instead of bailing.- Re-calling
autoAnimate(el)now destroys the previous controller. #234 (merged) already fixes the duplicate MutationObserver; destroying the old controller changes behavior for anyone who keeps the first controller around (e.g. calls.disable()on it later). Can you rebase on master and drop that part? - Please drop the
tsconfigtarget bump (es2019 → es2021) — that changes the code we ship to every consumer, so it needs its own discussion. Same for the Playwright bump; happy to take it separately.
Rebase on master + those tweaks and I'd love to get it into the next release.
The added test case in memory.spec.ts reproduces a memory leak.
|
@justin-schroeder I'm working on the fixes you're asking for. However, the test uses WeakRef from Es2021, so I'll have to re-write it to work without. It'll still trigger roughly the same behaviour - but may be slightly less to the point. |
34ddabd to
855241e
Compare
|
I have implemented the requested fixes. With animations being removed, some tests didn't manage to pick up the animations actually happening due to a race condition - so I added i util function and updated the affected tests. Caveat: I can't run playwright 1.47 on my machine (Ubuntu 26.* isn't compatible with that version), so I have been running the tests on a more recent version of playwright. I don't think the updates to the tests should make a difference depending on the version, but you never know. |
Fixes: #180
I work in a large code base using FormKit, and in a big table (with a sticky header, a sticky left column, sorting, free text search, and data cards in modals) we trigger the bug as described pretty easily.
I have one commit adding a test, and one commit with the fix. The test is modeled on the behavior of
@formkit/addons.AI usage disclosure:
I used Github copilot CLI to help diagnose, and write the tests (which I edited somewhat for clarity). After having the problem pointed out to me, I wrote the fix and verified with the test.
I can answer any question you may have about the fix. If you want me to fix it some other way, I am open to suggestions.
I posted a question about whether there is interest in a PR in the support-forum on Discord:
https://discord.com/channels/793529058377072650/1545415305659027456/1545415305659027456
(Also, not that it should matter, but my employer is an enterprise customer.)
Cheers!