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
does not work with isomorphic react apps #2
Comments
why would you want any p5 stuff to render server side? |
No, I would not want to use it on the server of course. Problem is that with isomorphic/universal react apps the server will load the same JS as on the client, so the code is "isomorph". Some animation libraries use a shim or something like
So on the server |
Oh, I see what you mean. |
Unfortunately not - once I call 'import X from Y' in a component and this component get's loaded on the server, library + dependencies will be loaded. In 'react-p5-wrapper' p5.js is a dependency which causes the error. So if I am correct p5.js would need to implement the 'if (window)' which would then also work for 'react-p5-wrapper'. That's what I think, but there might be other ways I am not aware of. |
@kkarkos I wonder... would the new dynamic imports in ESNext fix this issue? |
This is still a big issue and causing me a lot of trouble. I tried dynamic importing and it almost worked, the browser rendered the canvas for a second and then crashed. Definitely would love to see this happen! |
@jay-manday @kkarkos Did you guys ever figure out a solution to this issue? It's killing me. |
Was facing this issue when trying to use If anyone else has a better solution, I'm all ears. |
@justinsunho are you saying you pulled p5 itself out as a dependency of the wrapper and then imported p5 via either CDN or from a .js file in componentDidMount()? I've been building a lot of gatsby sites in the last year and have been trying to get p5 working on and off throughout that time. I feel like i tried something like that once and failed, but if you got it to work and build in gatsby or netlify i want back in!!! Thanks |
@hifilorau I did eventually get it working. Although to be completely honest, I've been using gatsby to learn react so I'm not super sure if it's hacky or not. I ended up not using this wrapper and instead writing my own: https://github.com/justinsunho/website/tree/master/src/components I imported Check out I mainly based a lot of my work on @Jinksi's You can see my stuff in action at justinsunho.com, but keep in mind that it's all still in flux. Also, if you have any tips, I'm more than glad to hear them! Super new to react and gatsby and p5 have been such fun ways of learning about it. |
This seems to be working for me (using recommendations from this gatsby documentation page) The code below is Typescript, you'll need to alter it slightly if you are using regular JS. Create a new custom component which uses Loadable import Loadable from "@loadable/component"
export const loadableP5 = Loadable(() => import('react-p5-wrapper')) instead of importing P5Wrapper, import that custom component, then use it as usual. import {loadableP5 as P5Wrapper} from './loadableP5' |
Closing due to the solutions outlined above being viable. You can alternatively include the wrapper directly into your HTML output file using this UNPKG link and then use P5 as usual in the wrapper. |
Unfortunately p5 won't work with isomorphic react apps due to
window
anddocument
requirements. Any thoughts?The text was updated successfully, but these errors were encountered: