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

useObserve trait value stays undefined when used with world #13

Open
Ctrlmonster opened this issue Oct 25, 2024 · 6 comments
Open

useObserve trait value stays undefined when used with world #13

Ctrlmonster opened this issue Oct 25, 2024 · 6 comments

Comments

@Ctrlmonster
Copy link
Collaborator

Ctrlmonster commented Oct 25, 2024

Hey, didn't have the time yet to make a csb for this, but putting it down here so it doesn't get lost:

I had some issues with using useObserve with the world this morning, where the trait value would stay undefined, even though I knew it to exist. Can you double check that it works in one of your apps? (Otherwise I'll make a csb later on)

@krispya
Copy link
Member

krispya commented Nov 3, 2024

Can you clarify if this is a type or value issue?

@Ctrlmonster
Copy link
Collaborator Author

The actual runtime value was undefined

@krispya krispya changed the title useObserve trait value stays undefined when used with world (+ useQuery type) useObserve trait value stays undefined when used with world Nov 3, 2024
@krispya
Copy link
Member

krispya commented Nov 3, 2024

Then no, my test and naive set up in an actual app both show it working. Can you reproduce it? Or tell me how to reproduce the issue?

@Ctrlmonster
Copy link
Collaborator Author

Yeah I'll see if I can reproduce it in a csb tomorrow

@Ctrlmonster
Copy link
Collaborator Author

Ctrlmonster commented Nov 4, 2024

This should reproduce it:

function SceneContainer() {
  const world = useWorld();

  useEffect(() => {
    world.add(SomeTrait);
    return () => world.remove(SomeTrait);
  }, [world]);


  return (
    <Child />
  )
}


function Child() {
  const world = useWorld();
  const traitSnap = useObserve(world, SomeTrait);
  
  console.log(traitSnap); // <-- stays undefined until HMR or something else triggers another tree rerender

  return null;
}

@krispya
Copy link
Member

krispya commented Nov 12, 2024

Can you verify if this issue still exists with the latest version? This exact set up works with my tests and I believe v0.1.5 fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants