fengari-lua / fengari

🌙 φεγγάρι - The Lua VM written in JS ES6 for Node and the browser
MIT License
1.8k stars 64 forks source link

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

Open wqferr opened 10 months ago

wqferr commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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

wqferr commented 10 months ago

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

wqferr commented 10 months ago

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

daurnimator commented 10 months ago

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

wqferr commented 10 months ago

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.

daurnimator commented 10 months ago

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

wqferr commented 10 months ago

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