Closed Neptunium1129 closed 2 months ago
Can you provide a more minimal reproduction or at least a list of steps to reproduce and where to look at?
Can you provide a more minimal reproduction or at least a list of steps to reproduce and where to look at?
change code ModalLib.svelte
line 308
//let modalState = $state(defaultState);
let modalState = defaultState;
like this
let modalState = $state(defaultState);
//let modalState = defaultState;
In $effect you do showPopup(modalObj)
which calls open
which does
modalState = { ...defaultState, ...options };
updateStyleTransition(); // reads `modalState`
and congratulations, you got a dependency loop 🎉
Solution: wrap call of either showPopup
(preferable) or updateStyleTransition
with the untrack
.
If modalState
isn't modified after the assignment, you can just disable that warning.
In $effect you do
showPopup(modalObj)
which callsopen
which doesmodalState = { ...defaultState, ...options }; updateStyleTransition(); // reads `modalState`
and congratulations, you got a dependency loop 🎉
Solution: wrap call of either
showPopup
(preferable) orupdateStyleTransition
with theuntrack
.If
modalState
isn't modified after the assignment, you can just disable that warning.
$effect(()=>{
if(modalObj != null){
const a = untrack(() => {showPopup(modalObj)})
}
});
This is exactly the code I wanted. Thanks for the advice!
Describe the bug
my code is a loop bug when using the state function. this is code is "https://github.com/flekschas/svelte-simple-modal" migrate rune test mode.
Reproduction
REPL
Logs
No response
System Info
Severity
annoyance