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

createPolled memo()[1] is undefined

Open create-signal opened this issue 3 months ago • 2 comments

Describe the bug

We're encountering a problem while using the solid-primitives/date -> createDateNow method.

Internally it uses the createPolled method from solid-primitives/timer, which is throwing the error

memo()[1] is not a function. (In 'memo()[1](fn)', 'memo()[1]' is undefined)

This issue is only happening for a small subset of users in production. Unfortunately I can't reproduce it in development or stackblitz, and I can't spot any particular trend based on browser or device etc.

Looking at the source, I can't think of any reason why that setter would be undefined, but maybe a maintainer would have a better idea?

We're using the following versions: @solidjs/start @1.1.7 solid-js @1.9.5 solid-primitives/date @2.1.1

Minimal Reproduction Link

https://stackblitz.com/edit/github-9zo4dpy1?file=src%2FApp.tsx

create-signal avatar Aug 28 '25 00:08 create-signal

Stackblitz demo seems to work and there are no errors. Both in dev and build preview.

There actually was a bug in createPolled code, which I now corrected: https://github.com/solidjs-community/solid-primitives/commit/3eec5eb7339531a134d2f6d9046fd659edd5b80e

options were passed as a initial value to createMemo by mistake. While it shouldn't be passed to the memo at all because SignalOptions<T> != MemoOptions<Signal<T>>.

This suggests perhaps calling fn in createMemo(() => createSignal(fn(value), options), options) threw an error, which something caught and ignored, but it resulted in memo not updating from it's initial value, which in this case was options.

It may have actually been createDateNew that caused the initial error, because the options passed to createPolled are { equals: (a, b) => a.getTime() === b.getTime() }, which should throw when a, b are Signal<Date> not Date.

And because the value of memo stayed at options you get an error memo()[1] is not a function. (In 'memo()[1](fn)', 'memo()[1]' is undefined).

I don't really get how that would only throw for some of the users, and not for everybody, so it may not be this.

I'll release the patch, let me know if it changes anything.

thetarnav avatar Aug 28 '25 09:08 thetarnav

We kept seeing this error reported in our logs after updating to timer v1.4.3. I eventually wrote our own helpers that use createTimer directly and that seems ok.

function createDateNow(interval: number) {
  const [date, setDate] = createSignal(new Date());
  createTimer(() => setDate(new Date()), interval, setInterval);
  return date;
}

function createIntervalCounter(interval: number) {
  const [count, setCount] = createSignal(0);
  createTimer(() => setCount((count) => count + 1), interval, setInterval);
  return count;
}

create-signal avatar Sep 15 '25 06:09 create-signal