Comments (10)
Unfortunately the change doesn't seem to have worked.
Do you use build-time SSR and can successfully deploy?
I will be able to test changes to the code as soon as I am able to develop react-p5
locally 👍
from react-p5.
@Hahlh I think a workaround on that is to just not render canvas or load p5 in SSR mode because it doesn't make sense....it doesn't affect SEO or anything else if we will not render it in SSR
from react-p5.
because the problem here is actually with p5 itself but not with (react-p5
it just renders a
p5
needs access to window
etc.....that's why it throws errorsfrom react-p5.
You would normally implement type checks in your code that prevent errors during build:
Something like:
if (typeof window !== 'undefined') {
window.doSomething
}
In this case the error occurs directly in react-p5
, meaning that I can't do anything about it without changing react-p5
:
I am curious as surely other people must have it running with Gatsby?
Maybe @lambertbrady can weigh in as he proposed the first change to the window check in react-p5
?
Did it work for you after the change?
Did you additionally have to wrap all the react-p5
related code in a window-checker or was wrapping those directly referring to window
enough?
from react-p5.
Update:
If I comment all react-p5
related code out, it builds again successfully. So something in my code is triggering react-p5
and it in turn fails, because window
is undefined.
That should make the question to you, @lambertbrady, solved. Please excuse the unnecessary ping.
from react-p5.
As a side note:
This is what the error logged to the terminal looks like in this case:
I am not sure whether that is something that can be improved in react-p5
?
from react-p5.
Another update:
If I leave all the code unchanged and only comment out the Sketch component return, the code builds successfully.
So that should mean, that additional window
checks are required in react-p5
to prevent calls to p5
, that result in a window undefined
?
But it seems that p5
should also have fail-safes against this:
from react-p5.
@Hahlh as a workaround use dinamyc imports ....just to import this library when window is available othervise no. Example.
if(window) {
const Sketch = require(react-p5)
}
from react-p5.
I hope you are doing great!
let Sketch
if (typeof window !== "undefined") {
Sketch = require("react-p5")
}
works, although it's means mixing import
and require
and although the import should normally be top level?
The problem with this is, that it also somehow changes my setup, meaning where the canvas is placed etc.
I will now explore two alternative approaches from the Gatsby docs.
Customizing the webpack config to use a dummy module during build and using loadable-components.
If those don't succeed, I may try to force the setup to happen later with a useEffect, although I am not sure whether that will introduce scoping problems.
Thank you again for the fast help, @Gherciu !
from react-p5.
In the example above, using dynamic imports as you suggested, and in using a custom webpack config, the canvas seems to get attached to the wrong parent.
In this case the absolute div on the right side.
Could I do something about that or specify precisely what the parent element should be?
Edit:
The current workaround I am using for attaching the canvas to the correct element, is to conditionally render not only the <SketchComp />
, but all children of the main container.
This seems to work for the moment and I will now test it for deploying.
from react-p5.
Related Issues (20)
- Is it possible to change the image displayed with React image upload? HOT 2
- Problem with texture img when changing variable on click.
- How can I access to p5.Vector class? HOT 3
- Uncaught TypeError: particles[i].follow is not a function HOT 1
- Typing not available for the p5 declared in the window. HOT 1
- fft.waveform() doesn't return correct array
- issues with p5 sound library import HOT 3
- Cannot read properties of undefined (reading 'stringToGlyphs')
- Type errors appearing when implementing sketch in TS HOT 1
- Multiple instances of react-p5 don't seem to work HOT 2
- `noCanvas()` doesn't seem to work HOT 2
- windowWidth not defined HOT 2
- elements render twice requiring strict mode to be removed HOT 2
- stop sound if user navigates to another tab. HOT 1
- `window is not defined` even with the dynamic import on Next.js HOT 1
- Failed to load image in preload function HOT 1
- Can we update package.json to have the latest and greatest p5.js version? HOT 1
- Renderer for canvas? HOT 1
- Passing additional arguments to functions draw() and setup() HOT 1
- :boom: BUG: deconstruct not works ! HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-p5.