solid-primitives icon indicating copy to clipboard operation
solid-primitives copied to clipboard

createScheduled crashes solid when changing route

Open masylum opened this issue 6 months ago • 1 comments

Describe the bug

This is what's happening:

const scheduled = createScheduled((fn) => debounce(fn, 10_000))
const debouncedIsDirty = createMemo((prev: boolean) => {
  const current = isDirty()
  return scheduled() ? current : prev
}, isDirty())

createEffect(() => {
  if (!debouncedIsDirty()) return
  updatePost(props.post)
})


onCleanup(() => {
  if (!isDirty()) return
  updatePost(props.post)
})

I'm using createScheduled to debounce a memo. The idea is that when a form becomes dirty, we want to save that form. But we don't want to overwhelm the server, so we wait for 10s window. We also force saving the post on cleanup.

If I edit the form and then I click on a link to navigate away, the whole thing explodes. I've commented out the scheduled code, and it is indeed the culprit. I've also waited 10s, and it also works. It only happens when I navigate away during that time.

Image

Minimal Reproduction Link

I have no idea how to reproduce this in isolation

masylum avatar Jul 03 '25 21:07 masylum

This looks like a similar issue: https://github.com/solidjs/solid/pull/2062 No idea why it happens though.

thetarnav avatar Jul 03 '25 21:07 thetarnav