-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
fixing issue with announcer and hot module reloading #1585
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f7a08ed
fixing issue with announcer and hot module reloading
alexreardon 6e9e8ec
fixing broken tests
alexreardon 669d94f
adding logic for ref clearing
alexreardon 9ebcaf7
Merge branch 'master' of github.com:atlassian/react-beautiful-dnd int…
alexreardon f44b262
Merge branch 'master' into fixing-hmr
alexreardon 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
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -14,42 +14,46 @@ export default function useAnnouncer(contextId: ContextId): Announce { | |
const id: string = useMemo(() => getId(contextId), [contextId]); | ||
const ref = useRef<?HTMLElement>(null); | ||
|
||
useEffect(() => { | ||
invariant(!ref.current, 'Announcement node already mounted'); | ||
useEffect( | ||
function setup() { | ||
invariant(!ref.current, 'Announcement node already mounted'); | ||
|
||
const el: HTMLElement = document.createElement('div'); | ||
ref.current = el; | ||
const el: HTMLElement = document.createElement('div'); | ||
ref.current = el; | ||
|
||
// identifier | ||
el.id = id; | ||
// identifier | ||
el.id = id; | ||
|
||
// Aria live region | ||
// Aria live region | ||
|
||
// will force itself to be read | ||
el.setAttribute('aria-live', 'assertive'); | ||
el.setAttribute('role', 'log'); | ||
// must read the whole thing every time | ||
el.setAttribute('aria-atomic', 'true'); | ||
// will force itself to be read | ||
el.setAttribute('aria-live', 'assertive'); | ||
el.setAttribute('role', 'log'); | ||
// must read the whole thing every time | ||
el.setAttribute('aria-atomic', 'true'); | ||
|
||
// hide the element visually | ||
Object.assign(el.style, visuallyHidden); | ||
// hide the element visually | ||
Object.assign(el.style, visuallyHidden); | ||
|
||
// Add to body | ||
getBodyElement().appendChild(el); | ||
// Add to body | ||
getBodyElement().appendChild(el); | ||
|
||
return () => { | ||
// unmounting after a timeout to let any annoucements | ||
// during a mount be published | ||
setTimeout(function remove() { | ||
return function cleanup() { | ||
// grabbing and clearing ref incase effect is about to run again | ||
const toBeRemoved: ?HTMLElement = ref.current; | ||
invariant(toBeRemoved, 'Cannot unmount announcement node'); | ||
|
||
// Remove from body | ||
getBodyElement().removeChild(toBeRemoved); | ||
ref.current = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the fix here. Clearing the ref before the timeout |
||
}); | ||
}; | ||
}, [id]); | ||
|
||
// unmounting after a timeout to let any annoucements | ||
// during a mount be published | ||
setTimeout(function remove() { | ||
// Remove from body | ||
getBodyElement().removeChild(toBeRemoved); | ||
}); | ||
}; | ||
}, | ||
[id], | ||
); | ||
|
||
const announce: Announce = useCallback((message: string): void => { | ||
const el: ?HTMLElement = ref.current; | ||
|
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.
unrelated :D