-
Notifications
You must be signed in to change notification settings - Fork 14
Add ResizeObserver support to useUnicornScene hook #42
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
Merged
diegopeixoto
merged 5 commits into
main
from
31-canvas-does-not-resize-when-container-size-changes
Mar 23, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
473ca44
Add ResizeObserver support to useUnicornScene hook and update tests
diegopeixoto 4e9a692
Refactor test for ResizeObserver in useUnicornScene
diegopeixoto 4e67360
Update src/__tests__/useUnicornScene.test.ts
diegopeixoto cfb556f
Enhance useUnicornScene to handle absence of ResizeObserver
diegopeixoto c840ee8
Update package version to 2.1.4-1 in package.json
diegopeixoto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,9 @@ yarn-error.log* | |
| .vscode/ | ||
| .idea/ | ||
|
|
||
| # Playground | ||
| playground/ | ||
|
|
||
| # TypeScript | ||
| *.tsbuildinfo | ||
|
|
||
|
|
||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,38 @@ | ||
| import "@testing-library/jest-dom/vitest"; | ||
| import { vi } from "vitest"; | ||
|
|
||
| // jsdom does not provide ResizeObserver — provide a minimal mock that tracks | ||
| // observed elements and exposes a helper to simulate resize entries. | ||
| type ResizeCallback = (entries: ResizeObserverEntry[]) => void; | ||
|
|
||
| class MockResizeObserver { | ||
| static instances: MockResizeObserver[] = []; | ||
|
|
||
| callback: ResizeCallback; | ||
| elements: Set<Element> = new Set(); | ||
|
|
||
| constructor(callback: ResizeCallback) { | ||
| this.callback = callback; | ||
| MockResizeObserver.instances.push(this); | ||
| } | ||
|
|
||
| observe(target: Element) { | ||
| this.elements.add(target); | ||
| } | ||
| unobserve(target: Element) { | ||
| this.elements.delete(target); | ||
| } | ||
| disconnect = vi.fn(() => { | ||
| this.elements.clear(); | ||
| }); | ||
|
|
||
| /** Test helper: fire the callback with a minimal entry for `target`. */ | ||
| simulateResize(target: Element) { | ||
| const entry = { target } as ResizeObserverEntry; | ||
| this.callback([entry]); | ||
| } | ||
| } | ||
|
|
||
| vi.stubGlobal("ResizeObserver", MockResizeObserver); | ||
|
|
||
| export { MockResizeObserver }; |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.