feat(test): add vitest setup and widget container tests #3102
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