feat(test): add vitest setup and widget container tests#3102
Merged
adumesny merged 1 commit intogridstack:masterfrom Jul 28, 2025
Merged
feat(test): add vitest setup and widget container tests#3102adumesny merged 1 commit intogridstack:masterfrom
adumesny merged 1 commit intogridstack:masterfrom
Conversation
fix (fix gridstack#2937) - fix multiple grids crash. Implement WeakMap-based widget container tracking in GridStackRenderProvider - Configure vitest with jsdom environment in vite.config.ts - Add test scripts and dependencies to package.json - Add comprehensive test suite for widget container management
adumesny
reviewed
Jul 28, 2025
|
|
||
| "@asamuzakjp/css-color@^3.2.0": | ||
| version "3.2.0" | ||
| resolved "https://registry.npmmirror.com/@asamuzakjp/css-color/-/css-color-3.2.0.tgz#cc42f5b85c593f79f1fa4f25d2b9b321e61d1794" |
Member
There was a problem hiding this comment.
guess you're using npm instead of yarn, which I guess is fine...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes the issue where multiple GridStack instances would crash when using the React integration due to shared state in the static GridStack.renderCB callback (#2937).
Problem: The static GridStack.renderCB was being shared across all GridStack instances, causing widget container references to be mixed up between different grids. This led to crashes and incorrect behavior when multiple grids were present on the same page.
Solution: Implemented a WeakMap-based approach to store widget containers separately for each GridStack instance:
• Added a gridWidgetContainersMap WeakMap that uses the GridStack instance as the key
• Each grid instance now maintains its own isolated widget container map
• The WeakMap ensures automatic memory cleanup when grid instances are destroyed
the fix snippets:
This ensures that multiple GridStack instances can coexist safely without interfering with each other's widget management.
Checklist
Additional notes:
• Added comprehensive unit tests using Vitest to verify the WeakMap functionality
• Tests cover: multi-instance isolation, proper cleanup, and widget container management
• The solution maintains backward compatibility while fixing the multi-instance issue