Skip to content

createEffect does not work within createRoot #2569

@Sleepful

Description

@Sleepful

Describe the bug

I can't get createEffect to execute at all within a test/nodejs process...
I copied the documentation verbatim, Basic Usage code sample:

https://docs.solidjs.com/reference/reactive-utilities/create-root#basic-usage

and then ran it with node ./file.js, does not trigger an effect.

Is it a bug?

Your Example Website or App

just execute the sample code

Steps to Reproduce the Bug or Issue

copy this into a file:

import { createSignal, createEffect, createRoot } from "solid-js";
import { render } from "solid-js/web"

function createCounter(initial = 0) {
  const [count, setCount] = createSignal(initial);

  createEffect(() => {
    console.log(`Count changed, new value: ${count()}`);
  });

  function increment() {
    setCount((c) => c + 1);
  }

  function reset() {
    setCount(initial);
  }

  return { count, increment, reset };
}

createRoot((dispose) => {
  const { count, increment, reset } = createCounter(10);

  console.log(count())
  increment();
  console.log(count())
  reset();
  console.log(count())

  dispose();
});

and run the file with node ./file.js

Expected behavior

should print to console Count changed ... message, it does not print

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: nodejs
  • Version: ^1.9.10

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions