Skip to content
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

Fix useStageRerenderer hook in React.StrictMode #291

Merged
merged 2 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .codesandbox/ci.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Stage/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down