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

onLoop function not called in nuxt generate (SSG) but working in dev mode #97

Open
5 tasks done
dghez opened this issue Apr 11, 2024 · 2 comments
Open
5 tasks done
Assignees
Labels
bug Something isn't working p4-important-bug Violate documented behavior or significantly improve performance (priority) upstream Bug in a dependency of Tres

Comments

@dghez
Copy link

dghez commented Apr 11, 2024

I'm using nuxt with SSG, so running nuxt generate to build it,
I noticed this thing, everything works fine in dev mode, but when i build using generate the onLoop function never get called.
Attached I have the reproduction link

I'm running on

    "nuxt": "^3.11.2",
    "@tresjs/cientos": "^3.8.0",
    "@tresjs/core": "^3.8.0",
    "@tresjs/nuxt": "^2.1.1",

DEV MODE, as you can see it triggers the logs correctly, including the loop
image

BUILD, the onLoop never get triggered
image

Reproduction

https://stackblitz.com/edit/nuxt-starter-hsw5j9

Steps to reproduce

npm i
npm run dev
npm run generate

System Info

System:
    OS: macOS 14.4.1
    CPU: (8) x64 Apple M1
    Memory: 16.41 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
    npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
    pnpm: 8.6.7 - ~/Library/pnpm/pnpm
    bun: 1.0.17 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 122.1.63.169
    Chrome: 123.0.6312.107
    Safari: 17.4.1

Used Package Manager

npm

Code of Conduct

@dghez dghez changed the title onLoop function not called in nuxt generate, SSG but working in dev onLoop function not called in nuxt generate (SSG) but working in dev mode Apr 11, 2024
@alvarosabu alvarosabu self-assigned this Apr 11, 2024
@alvarosabu alvarosabu added bug Something isn't working p4-important-bug Violate documented behavior or significantly improve performance (priority) upstream Bug in a dependency of Tres labels Apr 11, 2024
@alvarosabu
Copy link
Member

As a workaround just call resume @dghez

const { onLoop, resume } = useRenderLoop();

console.log('BOX: GENERATE');

onLoop((state) => {
  if (mesh.value) {
    mesh.value.position.x = Math.sin(state.elapsed);
  }
});

resume();

https://stackblitz.com/edit/nuxt-starter-s6xuwx?file=components/Box.vue,package.json

@dghez
Copy link
Author

dghez commented Apr 12, 2024

For the lazy people, I've made an explicit composable so i'm sure I won't forget to call the resume

import { useRenderLoop } from '@tresjs/core'

export const useCustomFrame = (cb) => {
  const { onLoop, resume } = useRenderLoop()

  onLoop((state) => {
    cb(state)
  })

  resume()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p4-important-bug Violate documented behavior or significantly improve performance (priority) upstream Bug in a dependency of Tres
Projects
None yet
Development

No branches or pull requests

2 participants