@@ -130,19 +130,19 @@ export function useFocusScope({
130
130
}
131
131
}
132
132
133
- const unsubEvents = executeCallbacks (
134
- addEventListener ( document , "focusin" , handleFocusIn ) ,
135
- addEventListener ( document , "focusout " , handleFocusOut )
136
- ) ;
137
- const mutationObserver = new MutationObserver ( handleMutations ) ;
138
- if ( container ) {
133
+ return untrack ( ( ) => {
134
+ const unsubEvents = executeCallbacks (
135
+ addEventListener ( document , "focusin " , handleFocusIn ) ,
136
+ addEventListener ( document , "focusout" , handleFocusOut )
137
+ ) ;
138
+ const mutationObserver = new MutationObserver ( handleMutations ) ;
139
139
mutationObserver . observe ( container , { childList : true , subtree : true } ) ;
140
- }
141
140
142
- return ( ) => {
143
- unsubEvents ( ) ;
144
- mutationObserver . disconnect ( ) ;
145
- } ;
141
+ return ( ) => {
142
+ unsubEvents ( ) ;
143
+ mutationObserver . disconnect ( ) ;
144
+ } ;
145
+ } ) ;
146
146
} ) ;
147
147
148
148
$effect ( ( ) => {
@@ -161,8 +161,8 @@ export function useFocusScope({
161
161
162
162
$effect ( ( ) => {
163
163
if ( ! forceMount . current ) return ;
164
- let container = ref . current ;
165
164
enabled . current ;
165
+ const container = ref . current ;
166
166
const previouslyFocusedElement = document . activeElement as HTMLElement | null ;
167
167
untrack ( ( ) => {
168
168
handleMount ( container , previouslyFocusedElement ) ;
@@ -175,9 +175,7 @@ export function useFocusScope({
175
175
} ) ;
176
176
177
177
function handleMount ( container : HTMLElement | null , prevFocusedElement : HTMLElement | null ) {
178
- if ( ! container ) {
179
- container = document . getElementById ( id . current ) ;
180
- }
178
+ if ( ! container ) container = document . getElementById ( id . current ) ;
181
179
if ( ! container ) return ;
182
180
focusScopeStack . add ( focusScope ) ;
183
181
const hasFocusedCandidate = container . contains ( prevFocusedElement ) ;
0 commit comments