vhtml icon indicating copy to clipboard operation
vhtml copied to clipboard

SSR Memory leak

Open Shenmin-Z opened this issue 6 years ago • 4 comments

I recently added this package in our project and I was told it's causing memory leak in our prod env.

After reading the code, it seems like it's the sanitized cache that's causing the problem.

sanitized[s] = true;

Every generated html string(s) would be stored in this cache, and it seems to have caused our server run out of memory and keeps restarting.

Shenmin-Z avatar Jun 13 '19 01:06 Shenmin-Z

Has it been solved?

atlas1119 avatar Jul 01 '19 04:07 atlas1119

This is still an issue. Switching to a WeakMap would likely help. I opened a PR with a basic implementation.

developit avatar Dec 04 '19 03:12 developit

It seems like the problem has not been solved yet. Is there any plan? 😭

zhuscat avatar Jul 21 '22 13:07 zhuscat

I'm integrating part of this library in an experiment and ran into this issue.

another potential solution is to add an indicator to the "child" that it was generated by h() so no need to store any global collection. the child could add a property to the html string it returns (not sure if this has browser memory implications and it's kind of hacky).

or instead of returning the string s maybe return lightest possible object structure with a toString() method e.g. { h: true, toString() { return s; } }

luwes avatar Oct 08 '22 15:10 luwes