Open fewkz opened 1 week ago
This is a feature of Vide's Strict Mode to encourage writing pure effects that clean up properly. It's automatically enabled in Roblox Studio and defaults to false
in production.
If you need your code to run once in an effect (and you don't want to disable strict mode), one method is to defer the code and allow subsequent effect calls to cancel it:
Vide.effect(function()
local connection = RunService.Heartbeat:Once(function()
-- code here runs max once per frame
end)
cleanup(connection)
end)
You can also compare the current and previous state tracked by an effect and check whether that changed:
vide.effect(function(previous)
local current = state()
if current ~= previous then
-- code here only runs when state() changed
end
return current
end, state())
Using vide 0.3.1, latest version on wally Effects seem to always run twice when a source changes I assumed maybe reads also trigger effects, but that's not the cause: