Please enable debug.loadmodule so that I can reload modules

As a Roblox developer, it is currently too hard to cleanly hot reload modules

This is where I can load a module, change its sourcecode slightly, and reload it again with the new sourcecode, this isn’t possible with require since require caches the return of the module.

In most usecases, this is fine and expected behaviour, but in some usecases (most notably, component development with UI frameworks), it would be nicer if I could just flush the cached value and re-run the script.

The engine already has a function that acts as an alternative to flushing the return cache, its called debug.loadmodule, but its disabled behind the flag DebugEnableLoadModule. This function compiles the module, then returns the main prototype of a module. This can then be called with variadic arguments (or none), and respects changes in the source code.

This feature request suggests enabling it as, it would improve my development experience because I can then develop modules without needing to cut and paste them back in

18 Likes

Yes please, I am suffering the same thing, I wanna test the module without getting in the game, but i can’t test those changes live because there is no way to reload script unless you copy and replace it.

Before saying Reload Script button exists, it doesn’t work. I tried.

This would be really good debugging tool to have in overall so. Big support.

2 Likes

It’s not quite clear from your post – are you referring to reloading modules in Studio edit mode (and test sessions)?

1 Like

He means that when you use require() on a modulescript, if it’s done the first time, it will execute the script, return the result and from now on only return that result (AKA cache the result).
debug.loadmodule() would circumvent caching and force to execute the module to get the result.
Basically. require() when first time use on a module, the result is computed and then stored (as modules execute only once). While debug.loadmodule() will ALWAYS execute a module and return the result regardless if it already was executed or not.

2 Likes

ive ran into this issue as well in the past though i’ve made a habit to dump all the requires needed inside of the component’s init (or render if you’re using roact-hooks/roact17) while im developing UI and move them out of it once I’m done. Though debug.loadmodule would be a lot more user friendly than going down that route.

1 Like