Giter Site home page Giter Site logo

p5-wrapper / next Goto Github PK

View Code? Open in Web Editor NEW
16.0 1.0 2.0 187 KB

A NextJS specific library for the @P5-Wrapper/react project.

License: MIT License

TypeScript 100.00%
javascript react typescript component animation creative-coding graphics-programming nextjs p5 sketches

next's People


dependabot[bot] avatar imadi-arch avatar jamesrweb avatar renovate[bot] avatar yevdyko avatar


 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar



next's Issues

Sketch renders twice when using app router

Expected Behavior

Sketch elements only contains one canvas

Actual Behavior

Sketch contains two? No clue why, but even in the most basic case when using the latest next.js, you get two sketches rendering.
Screenshot 2023-10-19 at 5 17 53 PM

The actual component renders it twice.
Screenshot 2023-10-19 at 5 18 07 PM

I've tried using p5-wrapper directly, with the same outcome.

Steps to Reproduce the Problem

  1. Create a new next js app, using app router.
  2. Add the snippet as is described.
  3. Get two sketches.

I've made a minimal reproduction. Notice how this happens in app router, but not page router.


Package Version: 0.2.0

Using Plugins in latest versions of Next.js

Have followed the steps in the @p5-wrapper/react documentation. However getting stuck at the top level await step. As that's not supported in the latest versions of nextjs using swc (instead of webpack)

Is there a way you can suggest I can import the sound plugin without top level await and get it to work.

Failed loading p5 wrapper

Expected Behavior

p5.js canvas can be inserted into page

Actual Behavior

Wrapper failed to load, throwing the error:

Module parse failed: Identifier 'je' has already been declared (7762:41)
|                                 if (F ? k || ($ = !0, A(), k = !0) : $ = !!je.first, H = Math.max(0, Math.floor(H)), Q = Math.max(0, Math.floor(Q)), $) {
|                                     if (!re) throw new Error("First frame must include a { palette } option");
>                                     var [je, we, fe, De, he = 8] = [
|                                         G,
|                                         H,
Import trace for requested module:

Steps to Reproduce the Problem

  1. Install @p5-wrapper/next
  2. Include <NextReactP5Wrapper /> component into page


Package Version: 1.0.2
Next Version: 14.1.0

unexpected array behavior inside p5 sketch function

I run into an issue when porting a cellular automaton I coded in standard p5.js to a Next.js project. I managed to isolate the bug that I suppose is responsible for the code not working. Here's the isolated issue:

My files

The contents of index.js

import Head from 'next/head'
import Issue from '@/components/p5/Issue'

export default function Home() {
  return (
        <meta name="description" content="Generated by create next app" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
      <div className='w-screen h-screen relative'>
        <Issue />

The contents of issue.jsx

import React from "react";
import { NextReactP5Wrapper } from "@p5-wrapper/next";

const sketch = p5 => {
    let board
    let size = 10
    p5.setup = () => {
        p5.createCanvas(200, 200)
        board = new Array(size);
        for (let i = 0; i < size; i++) {
            board[i] = new Array(size);
    const cokurwa = () => {
        console.log('before for:', board)
        console.log('before for:', board[1][0])
        for (let i = 0; i < board.length; i++) {
            board[i][0] = i;
        console.log('after for:', board)
        console.log('after for:', board[1][0])

const Issue = () => {
    return (
        <NextReactP5Wrapper sketch={sketch} />

export default Issue

Expected Behavior

  1. the sketch function is executed once
  2. console.log('before for:', board) in cokurwa() outputs a 2d array where each element is undefined
  3. console.log('before for:', board[1][0]) in cokurwa() outputs undefined

Actual Behavior


  1. the sketch function is executed two times, instead of one
  2. console.log('before for:', board) seems to output contents of board after the for loop has executed
  3. console.log('before for:', board[1][0]) outputs undefined like it logically should

Steps to Reproduce the Problem

  1. Paste the code I attached in the "My files" section to a create-next-app setup


Package Version: "@p5-wrapper/next": "^0.2.0"

There are types at 'c:/****/node_modules/@p5-wrapper/next/dist/main.d.ts', but this result could not be resolved when respecting package.json "exports". The '@p5-wrapper/next' library may need to update its package.json or typings.ts

Could not find a declaration file for module '@p5-wrapper/next'. 'c://node_modules/@p5-wrapper/next/dist/next.js' implicitly has an 'any' type.
There are types at 'c:/
/node_modules/@p5-wrapper/next/dist/main.d.ts', but this result could not be resolved when respecting package.json "exports". The '@p5-wrapper/next' library may need to update its package.json or typings.ts(7016)

i use typescript, how solved it?

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Other Branches

These updates are pending. To force PRs open, click the checkbox below.

  • Update dependency @types/node to v20.8.9
  • Update dependency rimraf to v5.0.5
  • Update react monorepo (@types/react, @types/react-dom)
  • Update dependency @vitejs/plugin-react to v4.1.0
  • Update dependency typescript to v5.2.2
  • Update dependency vite to v4.5.0
  • Update dependency vite-plugin-dts to v3.6.2

Detected dependencies

  • P5-wrapper/setup-action v1.0.6
  • P5-wrapper/setup-action v1.0.6
  • JS-DevTools/npm-publish v3
  • P5-wrapper/setup-action v1.0.6
  • stefanzweifel/git-auto-commit-action v5.0.0
  • P5-wrapper/setup-action v1.0.6
  • stefanzweifel/git-auto-commit-action v5
  • P5-wrapper/setup-action v1.0.6
  • stefanzweifel/git-auto-commit-action v5
  • P5-wrapper/setup-action v1.0.6
  • P5-wrapper/setup-action v1.0.6
  • actions/checkout v4
  • github/codeql-action v2
  • github/codeql-action v2
  • next ^13.3.4
  • react ^18.2.0
  • react-dom ^18.2.0
  • @types/node ^20.0.0
  • @types/react ^18.2.0
  • @types/react-dom ^18.2.1
  • @vitejs/plugin-react ^4.0.0
  • rimraf ^5.0.0
  • typescript ^5.0.4
  • vite ^4.3.4
  • vite-plugin-dts ^3.0.0
  • @p5-wrapper/react >= 4.2.0
  • next >= 12.3.4
  • react >= 18.2.0
  • react-dom >= 18.2.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.