fengari icon indicating copy to clipboard operation
fengari copied to clipboard

Seemingly random "snapshots" when requiring a module that returns a table

Open wqferr opened this issue 1 year ago • 9 comments

I'm trying to use Fengari on a personal project, but it sometimes just... stops updating my module return values? For instance, I'll add a new function to the table, and then Fengari just decides it doesn't exist. Every other field previous to that is fine, but the new one disappears.

I've tried restarting my web server to no avail, I'm kind of lost at this point. I want to use Fengari but this is making it really difficult for me.

wqferr avatar Nov 11 '23 20:11 wqferr

The only solution I see presently is to port my entire application over to JS and use Fengari exclusively to load my libraries... Which I'd rather not do.

wqferr avatar Nov 11 '23 20:11 wqferr

OK so progress on the problem: it seems my editor wasn't updating the file's last edited timestamp, not sure why that would ever happen, but once I touched the file, it instantly updated. This will serve as a workaround for now.

Not sure there's anything you can (or should) do with this issue, this is very clearly a problem with my setup. I'll leave the issue open to let you know what happened and see what you do (if you do) anything about it.

wqferr avatar Nov 11 '23 21:11 wqferr

NOPE never mind, touching the file doesn't always work. I'm lost guys, please help.

wqferr avatar Nov 11 '23 21:11 wqferr

Further testing seems to show that it only ever happens in Firefox, but I need to investigate more

wqferr avatar Nov 11 '23 22:11 wqferr

Testing concluded this still happens on chrome. No idea what causes it. It's not caching (at least not in any form I can disable).

wqferr avatar Nov 11 '23 22:11 wqferr

Are you just running into the fact that require caches the loaded module?

daurnimator avatar Nov 12 '23 10:11 daurnimator

Wouldn't touching the file invalidate the cache? Also how does it cache the module between server restarts? Do you save the module elsewhere on the disk?

Also if that were the case, I wouldn't simultaneously have a different problem: when multiple files require the same module, they get different copies. I know this because one of my modules does a metatable comparison, and in one file it was passing while not in the other.

Is there a way to disable these functions? They are getting in the way more than helping.

Thank you for the quick reply though.

wqferr avatar Nov 12 '23 17:11 wqferr

require in fengari caches until the page is reloaded. It's not related to the server side

https://www.lua.org/manual/5.4/manual.html#pdf-require

daurnimator avatar Nov 12 '23 22:11 daurnimator

Then the behavior I encountered wasn't caching, because it kept happening even when force reloading the page with no cache.

wqferr avatar Nov 13 '23 00:11 wqferr