Skip to content

Fix/formkit memory leak - #242

Open
filiphazardous wants to merge 8 commits into
formkit:masterfrom
filiphazardous:fix/formkit-memory-leak
Open

filiphazardous wants to merge 8 commits into
formkit:masterfrom
filiphazardous:fix/formkit-memory-leak

Conversation

@filiphazardous

Copy link
Copy Markdown

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!

@vercel

vercel Bot commented Sep 10, 2026

Copy link
Copy Markdown

@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 justin-schroeder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, and for the test 🙏 — the polling-timer cleanup is exactly right. A few things before it can land:

  1. destroy() becomes a no-op mid-animation — if (animations.has(el) && ... !== 'finished') return means 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.
  2. 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?
  3. Please drop the tsconfig target 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.

@filiphazardous

Copy link
Copy Markdown
Author

@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.

@filiphazardous
filiphazardous force-pushed the fix/formkit-memory-leak branch from 34ddabd to 855241e Compare November 20, 2026 15:05
@filiphazardous

Copy link
Copy Markdown
Author

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.

This branch has not been deployed

No deployments
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 this pull request may close these issues.

Memory Leak

2 participants