Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createPolled fires twice on load #632

Closed
apatrida opened this issue May 22, 2024 · 1 comment · Fixed by #687
Closed

createPolled fires twice on load #632

apatrida opened this issue May 22, 2024 · 1 comment · Fixed by #687
Labels
bug Something isn't working

Comments

@apatrida
Copy link

Describe the bug

I have a createPolled in a solidjs component, and it calls a server API. This API is only called from the create polled and nowhere else.

createPolled(
    async () => {
      await checkLiveStreams();
    },
    4 * 60 * 1000
);

This fires twice on page load.

If I do a makeTimer (w/interval) for the same, and a makeTimer (w/timeout at 1 second) to do the same basic work, everything happens as expected.

in the attached sample https://stackblitz.com/edit/github-rx3d4k?file=src%2FApp.tsx
you can see the console log "polled item" twice on refresh.

Minimal Reproduction Link

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

@thetarnav
Copy link
Member

createPolled is meant to be used for derivations (preferably pure) so it shouldn't matter that much.
But it is a bug regardless.
And it's easy to spot why from the source code:

const [polled, setPolled] = createSignal(untrack(fn.bind(void 0, value))); // <- calls fn
const update = () => setPolled(fn);
createComputed(update); // <- calls fn

@thetarnav thetarnav added the bug Something isn't working label Sep 8, 2024
@thetarnav thetarnav linked a pull request Sep 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants