Skip to content

refactor: enhance closed layer management and rendering logic in Tile…#52

Merged
kimgh06 merged 1 commit into
mainfrom
fix/textureload
Sep 30, 2025
Merged

refactor: enhance closed layer management and rendering logic in Tile…#52
kimgh06 merged 1 commit into
mainfrom
fix/textureload

Conversation

@kimgh06

@kimgh06 kimgh06 commented Sep 30, 2025

Copy link
Copy Markdown
Contributor

…map component

  • Introduced useState to manage the readiness of the closed layer.
  • Updated useLayoutEffect to ensure proper handling of closed layer visibility based on window dimensions and tile size.
  • Improved the ref assignment for the closed layer container to set its readiness state correctly.

…map component

- Introduced useState to manage the readiness of the closed layer.
- Updated useLayoutEffect to ensure proper handling of closed layer visibility based on window dimensions and tile size.
- Improved the ref assignment for the closed layer container to set its readiness state correctly.
Copilot AI review requested due to automatic review settings September 30, 2025 13:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the closed layer management in the Tilemap component to improve rendering reliability by introducing state-based readiness tracking. The changes ensure the closed layer container is properly initialized before attempting to populate it with sprites.

Key changes:

  • Added state management for closed layer readiness using useState
  • Consolidated closed layer pool management and sprite application into a single useLayoutEffect
  • Enhanced ref assignment with readiness state setting

while (usedIdx < current.length) current[usedIdx].outer.visible = current[usedIdx++].inner.visible = false;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [tiles]);
}, [tiles, windowWidth, windowHeight, tileSize, zoom, closedLayerReady]);

Copilot AI Sep 30, 2025

Copy link

Choose a reason for hiding this comment

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

The dependency array includes closedLayerReady which will cause this effect to re-run every time the closed layer becomes ready. Since closedLayerReady only changes from false to true once, consider using a ref or removing this dependency to avoid unnecessary re-executions.

Suggested change
}, [tiles, windowWidth, windowHeight, tileSize, zoom, closedLayerReady]);
}, [tiles, windowWidth, windowHeight, tileSize, zoom]);

Copilot uses AI. Check for mistakes.
Comment on lines +426 to +429
ref={node => {
closedLayerRef.current = node;
if (node) setClosedLayerReady(true);
}}

Copilot AI Sep 30, 2025

Copy link

Choose a reason for hiding this comment

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

The ref callback function is recreated on every render, which can cause unnecessary re-renders. Consider using useCallback to memoize this function.

Copilot uses AI. Check for mistakes.
@kimgh06 kimgh06 merged commit 4d64c1c into main Sep 30, 2025
1 check passed
@kimgh06 kimgh06 deleted the fix/textureload branch December 23, 2025 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants