From 5ce9e992888da8800f33c6adea1f70b9e8edca4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ochman?= Date: Tue, 11 Oct 2022 13:01:08 +0200 Subject: [PATCH 1/2] Fix useStageRerenderer hook in React.StrictMode --- CHANGELOG.md | 4 ++++ src/Stage/hooks.js | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cdc1041..893cf3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Fixed +- Fix `useStageRerenderer` hook in `React.StrictMode` ([#285]) + ## [1.0.3] - 2022-10-11 @@ -476,6 +479,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). [0.1.1]: https://github.com/michalochman/react-pixi-fiber/compare/v0.1.0...v0.1.1 [#286]: https://github.com/michalochman/react-pixi-fiber/pull/286 +[#285]: https://github.com/michalochman/react-pixi-fiber/issues/285 [#283]: https://github.com/michalochman/react-pixi-fiber/pull/283 [#277]: https://github.com/michalochman/react-pixi-fiber/pull/277 [#227]: https://github.com/michalochman/react-pixi-fiber/issues/227 diff --git a/src/Stage/hooks.js b/src/Stage/hooks.js index f61a70e..63af067 100644 --- a/src/Stage/hooks.js +++ b/src/Stage/hooks.js @@ -62,7 +62,7 @@ export function useStageRerenderer(props, appRef, canvasRef) { // eslint-disable-next-line react-hooks/exhaustive-deps useLayoutEffect(() => { // This is first render, no need to do anything - if (!appRef.current) return; + if (!appRef.current || prevProps === emptyObject) return; const { app } = props; @@ -83,7 +83,7 @@ export function useStageRerenderer(props, appRef, canvasRef) { const view = canvasRef.current; // We need to create new PIXI.Application when options other than dimensions - // are changed because some of the renderer settings are immutable. + // are changed because some renderer settings are immutable. if (!shallowEqual(otherOptions, prevOtherOptions)) { // Destroy PIXI.Application cleanupStage(appRef.current, STAGE_OPTIONS_RECREATE); @@ -121,7 +121,7 @@ export default function createStageFunction() { // The order is important here to avoid unnecessary renders or extra state: // - useStageRerenderer: // - is no-op first time it is called, because PIXI.Application is not created yet - // - is responsible + // - is responsible for applying changes to existing PIXI.Application // - useStageRenderer: // - is only called once // - is responsible for creating first PIXI.Application and destroying it when Stage is finally unmounted From 4fa8419d648187e21d774582576c83ed86f1b53b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ochman?= Date: Tue, 11 Oct 2022 13:07:09 +0200 Subject: [PATCH 2/2] Add more CodeSandbox sandboxes for CI --- .codesandbox/ci.json | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.codesandbox/ci.json b/.codesandbox/ci.json index 630b752..6a442c3 100644 --- a/.codesandbox/ci.json +++ b/.codesandbox/ci.json @@ -1,3 +1,14 @@ { - "sandboxes": ["new", "react-ts", "/examples"] + "sandboxes": [ + "new", + "react-ts", + "/examples", + "react-pixi-fiber-template-ohk6z", + "react-pixi-fiber-typescript-template-613ly", + "q7oj1p0jo6", + "react-pixi-fiber-demo-animatedsprite-d6udu", + "react-pixi-fiber-text-alignment-th5eg", + "react-pixi-fiber-with-redux-g4k7n", + "9qyxrljyo" + ] }