Repository navigation
fix(core): page scroll and selection locks are one per page across Core loads (AST-110 FR3) #10822
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
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8dd1933
test(core): each shared-realm shape gives the package and a copy one …
cixzhang 6392e53
feat(core): shared-realm helpers hold every kind of cross-module state
cixzhang 460632c
chore(changeset): note the internal shared-realm helpers
cixzhang 1677454
feat(core): sharedForReact keeps a React-bound shared value one per R…
cixzhang 9aca48d
fix(core): reset shared state without a dynamic delete
cixzhang 53b6023
fix(core): a shared brand's type member is required
cixzhang 3915114
spec(AST-110): FR3 states the observable slot guarantee; the mechanis…
cixzhang be43594
test(core): a scroll lock from a swizzled copy keeps the package's pa…
cixzhang 4446e5e
fix(core): the page scroll lock is one per page across swizzled copies
cixzhang 2d7d70c
fix(core): type the shared scroll-claim stacks
cixzhang 3b00d66
test(core): import the scroll-lock module types
cixzhang 4cbecd6
chore(changeset): describe the shared scroll and selection locks accu…
cixzhang 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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [fix] Two loads of Core's scroll-lock modules on one page now share one page scroll lock: closing the overlay that opened first no longer unlocks the page while the other overlay is still open. Text-selection locks, which a swizzled copy carries, are shared the same way, so a copy's release no longer restores a selection lock the package still holds. No API changes. | ||
|
|
||
| @cixzhang |
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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [chore] Internal: Core's shared-realm module gains helpers for state that the package and a swizzled copy share (state, maps, stores, brands and sequences). No API or behavior changes. | ||
|
|
||
| @cixzhang |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| /** | ||
| * @file useScrollLock.shared.test.ts | ||
| * @input Two loads of useScrollLock and its modules, as the package and a | ||
| * swizzled copy each carry one | ||
| * @output Proves the page stays locked while a lock from either load holds, | ||
| * and comes back to its own style after the last release | ||
| * @position Shared-state tests for useScrollLock.ts and rootScrollStyles.ts | ||
| * (spec:AST-110 FR3) | ||
| */ | ||
|
|
||
| import {cleanup, renderHook} from '@testing-library/react'; | ||
| import {afterEach, describe, expect, it, vi} from 'vitest'; | ||
| import type * as RootStylesModule from './rootScrollStyles'; | ||
| import type * as ScrollLockModule from './useScrollLock'; | ||
|
|
||
| /** One load of the scroll-lock modules, as the package or a copy has. */ | ||
| async function load(): Promise<{ | ||
| useScrollLock: typeof ScrollLockModule.useScrollLock; | ||
| isScrollLockActive: typeof RootStylesModule.isScrollLockActive; | ||
| }> { | ||
| vi.resetModules(); | ||
| const {useScrollLock} = await import('./useScrollLock'); | ||
| const {isScrollLockActive} = await import('./rootScrollStyles'); | ||
| return {useScrollLock, isScrollLockActive}; | ||
| } | ||
|
|
||
| afterEach(async () => { | ||
| cleanup(); | ||
| (await import('../utils/sharedRealm')).resetSharedStateForTest('hooks/'); | ||
| vi.resetModules(); | ||
| document.documentElement.style.overflow = ''; | ||
| }); | ||
|
|
||
| describe('a scroll lock shared by the package and a swizzled copy', () => { | ||
| it('keeps the page locked while the other load still holds a lock', async () => { | ||
| const pkg = await load(); | ||
| const copy = await load(); | ||
| const pkgLock = renderHook(() => pkg.useScrollLock(true)); | ||
| const copyLock = renderHook(() => copy.useScrollLock(true)); | ||
| expect(document.documentElement.style.overflow).toBe('hidden'); | ||
|
|
||
| pkgLock.unmount(); | ||
| // The copy's overlay is still open, so the page must stay locked. | ||
| expect(document.documentElement.style.overflow).toBe('hidden'); | ||
| expect(pkg.isScrollLockActive()).toBe(true); | ||
|
|
||
| copyLock.unmount(); | ||
| expect(document.documentElement.style.overflow).toBe(''); | ||
| expect(copy.isScrollLockActive()).toBe(false); | ||
| }); | ||
|
|
||
| it("restores the page's own overflow after the last release, in either order", async () => { | ||
| document.documentElement.style.overflow = 'auto'; | ||
| const pkg = await load(); | ||
| const copy = await load(); | ||
| const copyLock = renderHook(() => copy.useScrollLock(true)); | ||
| const pkgLock = renderHook(() => pkg.useScrollLock(true)); | ||
| copyLock.unmount(); | ||
| expect(document.documentElement.style.overflow).toBe('hidden'); | ||
| pkgLock.unmount(); | ||
| expect(document.documentElement.style.overflow).toBe('auto'); | ||
| }); | ||
| }); |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking: a swizzled overlay already reaches this module through the package's
useScrollLock, so this is not the reason for the shared state. Shortest rewrite: "Every copy of Core uses this one state, so locks from two copies stack on one page."