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

Re-evaluation of props defaults when using render functions and on prop update triggered from parent #999

Closed
nestarz opened this issue Apr 20, 2020 · 2 comments
Labels
🐞 bug Something isn't working

Comments

@nestarz
Copy link

nestarz commented Apr 20, 2020

Version

3.0.0-beta.2

Reproduction link

https://codesandbox.io/s/amazing-platform-m9ri1?file=/index.html

Steps to reproduce

I did setup a setInterval that update a reactive value that is sent as a prop to a child. I also added a way to see if the props are re-evaluated so it adds a text log in the DOM. This way you can see the behaviour directly.

What is expected?

Each prop update doesn't trigger a re-evaluation of the default functions.

What is actually happening?

A prop update trigger a re-evaluation of the default functions.


I am trying to make something like react-three-fiber. I can't "hoist" values of the defaults, because this mean all boxes that rely on a default value will share the same data.

Oddly, it works well using the template and not the render function.

@nestarz nestarz changed the title Re-evaluation of props when using render functions and on prop update triggered from parent Re-evaluation of props defaults when using render functions and on prop update triggered from parent Apr 20, 2020
@pikax
Copy link
Member

pikax commented Apr 20, 2020

As far as I know when you return render function from setup, it will re-render every time creating a new component, but you can simulate the render by creating the render blocks your self here

// NOTE HACK

  const App = {
    setup() {
      const position = ref(new THREE.Vector3(-1, 1, 0));
      setInterval(() => {
        position.value = new THREE.Vector3(Math.random(), 1, 0);
      }, 1000);

      return {
        position
      };
    },
    render(_ctx, _cache) {
      return (
        openBlock(),
        createBlock(Box, { position: _ctx.pos }, null, 8 /* PROPS */, [
          "position"
        ])
      );
    }
  };

@yyx990803 yyx990803 added the 🐞 bug Something isn't working label Apr 20, 2020
@yyx990803
Copy link
Member

btw, it's better to use shallowRef for Three.js objects to avoid observing them (since you are creating new vectors on each update and not mutating them)

pikax pushed a commit to pikax/vue-next that referenced this issue Apr 29, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Nov 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants