Skip to content

Conversation

@yevdyko
Copy link
Contributor

@yevdyko yevdyko commented Aug 21, 2025

@jamesrweb As we discussed, here is a proposal for renaming the component. What do you think?

PR Type

  • πŸ› Bug Fix
  • ✨ New Feature
  • πŸ”¨ Code Refactor
  • πŸ“ Documentation Update
  • πŸ§ͺ Test Update
  • πŸ”§ Build/CI Update
  • 🧹 Chore
  • βͺ Revert

Description

This PR refactors the ReactP5Wrapper component by renaming it to P5Canvas and updating all corresponding references throughout the codebase.

The new name clearly communicates that the component renders a p5.js canvas, rather than serving as a generic wrapper. It also aligns with common React naming conventions for components that directly represent rendered elements.

The original name ReactP5Wrapper was somewhat ambiguous, implying a higher-order component or general wrapper rather than a canvas-rendering component.

By renaming it to P5Canvas:

  • Developers can immediately understand that the component is responsible for rendering a p5.js canvas.
  • Code readability and maintainability are improved.

Overall, this refactor helps future contributors quickly grasp the component’s purpose and reduces potential confusion.

Proposed Changes

  • Change component name from ReactP5Wrapper to P5Canvas
  • Rename ReactP5WrapperGuard to P5CanvasGuard
  • Rename ReactP5WrapperWithSketch to P5CanvasWithSketch
  • Rename P5WrapperProps to P5CanvasProps
  • Rename P5WrapperPropsWithSketch to P5CanvasPropsWithSketch
  • Rename P5WrapperClassName to CanvasContainerClassName
  • Update data-testid wrapper to canvas-container
  • Rename WrapperRef to CanvasContainerRef
  • Rename CanvasInstanceRef to P5CanvasInstanceRef
  • Rename userProvidedProps to sketchProps
  • Rename removeCanvasInstance to removeP5CanvasInstance
  • Rename updateCanvasInstance to updateP5CanvasInstance
  • Rename createCanvasInstance to createP5CanvasInstance
  • Rename Wrapper to CanvasContainer
  • Actualize test descriptions

How Has This Been Tested?

  • Unit Tests
  • Integration Tests
  • Manual Testing (please describe)

Tested the demo application locally and checked all sketches still run as expected. Also ran the test suite and all existing tests pass without changes.

Screenshots

image

Breaking Changes

  • Yes (please describe)
  • No

Migration Notes

This PR introduces a component and type rename, which is a breaking change.

  1. JSX usage ReactP5Wrapper -> P5Canvas

Before:

import { ReactP5Wrapper } from "@p5-wrapper/react";

<ReactP5Wrapper sketch={mySketch} />

After:

import { P5Canvas } from "@p5-wrapper/react";

<P5Canvas sketch={mySketch} />
  1. TypeScript types

2.1. P5WrapperProps -> P5CanvasProps

Before:

import * as React from "react";
import { P5CanvasInstance, P5WrapperProps, ReactP5Wrapper } from "@p5-wrapper/react";

function sketch(p5: P5CanvasInstance) {
  p5.setup = () => p5.createCanvas(600, 400, p5.WEBGL);

  p5.updateWithProps = (props: P5WrapperProps) => {
    if (props.rotation) {
      rotation = (props.rotation * Math.PI) / 180;
    }
  };

  p5.draw = () => {
    p5.background(250);
    p5.normalMaterial();
    p5.push();
    p5.rotateZ(p5.frameCount * 0.01);
    p5.rotateX(p5.frameCount * 0.01);
    p5.rotateY(p5.frameCount * 0.01);
    p5.plane(100);
    p5.pop();
  };
}

export function App() {
  return <ReactP5Wrapper sketch={sketch} />;
}

After:

import * as React from "react";
import { P5CanvasInstance, P5CanvasProps, P5Canvas } from "@p5-wrapper/react";

function sketch(p5: P5CanvasInstance) {
  p5.setup = () => p5.createCanvas(600, 400, p5.WEBGL);

  p5.updateWithProps = (props: P5CanvasProps) => {
    if (props.rotation) {
      rotation = (props.rotation * Math.PI) / 180;
    }
  };

  p5.draw = () => {
    p5.background(250);
    p5.normalMaterial();
    p5.push();
    p5.rotateZ(p5.frameCount * 0.01);
    p5.rotateX(p5.frameCount * 0.01);
    p5.rotateY(p5.frameCount * 0.01);
    p5.plane(100);
    p5.pop();
  };
}

export function App() {
  return <P5Canvas sketch={sketch} />;
}

2.2. P5WrapperClassName -> CanvasContainerClassName

Before:

import { P5WrapperClassName, ReactP5Wrapper } from "@p5-wrapper/react";
import styled, { createGlobalStyle } from "styled-components";

const GlobalWrapperStyles = createGlobalStyle`
  .${P5WrapperClassName} {
    position: relative;
  }
`;

const StyledCentredText = styled.span`
  .${P5WrapperClassName} & {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 2rem;
    margin: 0;
    text-align: center;
  }
`;

export function App() {
  const [rotation, setRotation] = useState(0);

  useEffect(() => {
    const interval = setInterval(
      () => setRotation(rotation => rotation + 100),
      100
    );

    return () => {
      clearInterval(interval);
    };
  }, []);

  return (
    <Fragment>
      <GlobalWrapperStyles />
      <ReactP5Wrapper sketch={sketch} rotation={rotation}>
        <StyledCentredText>Hello world!</StyledCentredText>
      </ReactP5Wrapper>
    </Fragment>
  );
}

After:

import { CanvasContainerClassName, P5Canvas } from "@p5-wrapper/react";
import styled, { createGlobalStyle } from "styled-components";

const GlobalWrapperStyles = createGlobalStyle`
  .${CanvasContainerClassName} {
    position: relative;
  }
`;

const StyledCentredText = styled.span`
  .${CanvasContainerClassName} & {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 2rem;
    margin: 0;
    text-align: center;
  }
`;

export function App() {
  const [rotation, setRotation] = useState(0);

  useEffect(() => {
    const interval = setInterval(
      () => setRotation(rotation => rotation + 100),
      100
    );

    return () => {
      clearInterval(interval);
    };
  }, []);

  return (
    <Fragment>
      <GlobalWrapperStyles />
      <P5Canvas sketch={sketch} rotation={rotation}>
        <StyledCentredText>Hello world!</StyledCentredText>
      </ReactP5Wrapper>
    </Fragment>
  );
}

No additional changes were made β€” only the component and type names have been updated.

Checklist

  • My code follows the code style of this project
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • My changes generate no new warnings

@yevdyko yevdyko self-assigned this Aug 21, 2025
@yevdyko yevdyko requested a review from jamesrweb as a code owner August 21, 2025 14:23
@github-actions
Copy link

github-actions bot commented Aug 21, 2025

Coverage report for commit: c34bc64
File: ./coverage/clover.xml

Cover β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” Freq.
   0% β”‚ β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ β”‚  0.0%
  10% β”‚ β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ β”‚  0.0%
  20% β”‚ β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ β”‚  0.0%
  30% β”‚ β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ β”‚  0.0%
  40% β”‚ β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ β”‚  0.0%
  50% β”‚ β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ β”‚  0.0%
  60% β”‚ β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ β”‚  0.0%
  70% β”‚ β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ β”‚  0.0%
  80% β”‚ β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ β”‚  0.0%
  90% β”‚ β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ β”‚  0.0%
 100% β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β”‚ 100.0%
      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
 *Legend:* β–ˆ = Current Distribution 
Summary - Lines: 100.00% | Methods: 100.00% | Branches: 91.30%
FilesLinesMethodsBranches
src/components
Β  Β P5Canvas.tsx100.00%100.00%100.00%
Β  Β P5CanvasGuard.tsx100.00%100.00%72.73%
Β  Β P5CanvasWithSketch.tsx100.00%100.00%88.89%
src/constants
Β  Β CanvasContainerClassName.ts100.00%100.00%100.00%
src/contracts
Β  Β CanvasContainer.ts100.00%100.00%100.00%
Β  Β CanvasContainerRef.ts100.00%100.00%100.00%
Β  Β InputProps.ts100.00%100.00%100.00%
Β  Β P5CanvasInstance.ts100.00%100.00%100.00%
Β  Β P5CanvasInstanceRef.ts100.00%100.00%100.00%
Β  Β P5CanvasProps.ts100.00%100.00%100.00%
Β  Β P5CanvasPropsWithSketch.ts100.00%100.00%100.00%
Β  Β Sketch.ts100.00%100.00%100.00%
Β  Β SketchProps.ts100.00%100.00%100.00%
Β  Β WithChildren.ts100.00%100.00%100.00%
Β  Β p5.ts100.00%100.00%100.00%
src
Β  Β main.tsx100.00%100.00%100.00%
src/utils
Β  Β createP5CanvasInstance.ts100.00%100.00%100.00%
Β  Β logErrorBoundaryError.ts100.00%100.00%100.00%
Β  Β propsAreEqual.ts100.00%100.00%100.00%
Β  Β removeP5CanvasInstance.ts100.00%100.00%100.00%
Β  Β updateP5CanvasInstance.ts100.00%100.00%100.00%
Β  Β withoutKeys.ts100.00%100.00%100.00%

πŸ€– comment via lucassabreu/comment-coverage-clover

@jamesrweb jamesrweb added the documentation Pull requests that update project documentation label Aug 21, 2025
Copy link
Member

@jamesrweb jamesrweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will also need to update all of the examples in the .github/README.md and also check the CI and CD workflows, just in case.

Otherwise looks good to me πŸš€

@yevdyko
Copy link
Contributor Author

yevdyko commented Aug 21, 2025

@jamesrweb Thanks for the quick review! I’ll update the README examples in a separate PR since we need to keep the old version for now, otherwise it could be confusing. I also checked the workflows and no changes needed.

BTW, do we want to move the tsconfig file from the root to the config directory? If so, I can create a PR for that.

@yevdyko yevdyko enabled auto-merge August 21, 2025 17:42
@jamesrweb
Copy link
Member

@jamesrweb Thanks for the quick review! I’ll update the README examples in a separate PR since we need to keep the old version for now, otherwise it could be confusing. I also checked the workflows and no changes needed.

BTW, do we want to move the tsconfig file from the root to the config directory? If so, I can create a PR for that.

I don't mind but I'd make the change in this PR and then I'll just deploy the new version, easy, so just update the README in this PR and then I can just deploy it after we merge this one.

@yevdyko yevdyko disabled auto-merge August 22, 2025 11:43
@yevdyko
Copy link
Contributor Author

yevdyko commented Aug 22, 2025

@jamesrweb Just updated the README. I’ll move the tsconfig in a separate PR.

@jamesrweb
Copy link
Member

What do you want to do with the tsconfig?

@jamesrweb jamesrweb merged commit b978e59 into master Aug 22, 2025
10 checks passed
@jamesrweb jamesrweb deleted the change-component-name branch August 22, 2025 11:57
@yevdyko
Copy link
Contributor Author

yevdyko commented Aug 22, 2025

@jamesrweb Move it to the config directory, right?

@jamesrweb
Copy link
Member

You don't have to but if you want to, feel free to make a PR for it, yeah.

@yevdyko
Copy link
Contributor Author

yevdyko commented Aug 22, 2025

Would you prefer to keep it in the root directory? I believe it was in the config directory before the refactoring some time ago.

@jamesrweb
Copy link
Member

Yeah because there were two configs in the config directory that the one in the root linked to but I rewrote them into one and refactored the other two out. I'm open to both options.

@yevdyko
Copy link
Contributor Author

yevdyko commented Aug 22, 2025

Yeah, let’s keep it as it is. I’ll go ahead and finally extract the common workflows into the newly created repository, as we discussed.

@yevdyko
Copy link
Contributor Author

yevdyko commented Aug 22, 2025

What are we still missing to make a final release of version 5?

@jamesrweb
Copy link
Member

Workflow migrations (the ones you'll do).

AND

End to end tests to cover p5@2.x.x changes (I'll do those).

@yevdyko
Copy link
Contributor Author

yevdyko commented Aug 22, 2025

Sounds good! Let's focus on that πŸ€–

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Pull requests that update project documentation enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants