Repository: servo/servo
File: components/constellation/constellation.rs (Rust)

Code before:
        // Override the viewport details if we have a pending change for that browsing context.
        let viewport_details = self
            .pending_viewport_changes
            .remove(&browsing_context_id)
            .unwrap_or(viewport_details);
        let browsing_context = BrowsingContext::new(
            bc_group_id,
            browsing_context_id,
            webview_id,
            pipeline_id,
            parent_pipeline_id,
            viewport_details,
            is_private,
            inherited_secure_context,
            throttled,
        );
        self.browsing_contexts
            .insert(browsing_context_id, browsing_context);

        if self.accessibility_active &&
            let Some(pipeline) = self.pipelines.get(&pipeline_id)
        {
            let _ = pipeline
                .event_loop
                .send(ScriptThreadMessage::SetAccessibilityActive(true));
        }

        // If this context is a nested container, attach it to parent pipeline.
        if let Some(parent_pipeline_id) = parent_pipeline_id {
            if let Some(parent) = self.pipelines.get_mut(&parent_pipeline_id) {
                parent.add_child(browsing_context_id);
            }
        }
    }

    fn add_pending_change(&mut self, change: SessionHistoryChange) {
        debug!(
            "adding pending session history change with {}",
            if change.replace.is_some() {
                "replacement"
            } else {
                "no replacement"
            },
        );
        self.pending_changes.push(change);
    }

    /// Handles loading pages, navigation, and granting access to `Paint`.
    #[servo_tracing::instrument(skip_all)]
    fn handle_request(&mut self) {
        #[expect(clippy::large_enum_variant)]

Review comment (suggestion):
Another option here is to store whether or not accessibility is enabled in each `ScriptThread` and then seed every new `Layout` with that information. That would avoid having the possibility of any "in between" time where accessibility seems to be disabled -- maybe a layout happens without it event.

This would require modifying the`EventLoop` creation code in `components/constellation/event_loop.rs`. For instance it could be a member of `InitialScriptState` which is used to initialize the state of a new `ScriptThread` (one per `EventLoop`). Then in each `ScriptThread` you would store the state and ensure that new `Layout`s have a11y enabled. 

Code after:
        // Override the viewport details if we have a pending change for that browsing context.
        let viewport_details = self
            .pending_viewport_changes
            .remove(&browsing_context_id)
            .unwrap_or(viewport_details);
        let browsing_context = BrowsingContext::new(
            bc_group_id,
            browsing_context_id,
            webview_id,
            pipeline_id,
            parent_pipeline_id,
            viewport_details,
            is_private,
            inherited_secure_context,
            throttled,
        );
        self.browsing_contexts
            .insert(browsing_context_id, browsing_context);

        if self.accessibility_active {
            if let Some(pipeline) = self.pipelines.get(&pipeline_id) {
                let _ = pipeline
                    .event_loop
                    .send(ScriptThreadMessage::SetAccessibilityActive(true));
            }
        }

        // If this context is a nested container, attach it to parent pipeline.
        if let Some(parent_pipeline_id) = parent_pipeline_id {
            if let Some(parent) = self.pipelines.get_mut(&parent_pipeline_id) {
                parent.add_child(browsing_context_id);
            }
        }
    }

    fn add_pending_change(&mut self, change: SessionHistoryChange) {
        debug!(
            "adding pending session history change with {}",
            if change.replace.is_some() {
                "replacement"
            } else {
                "no replacement"
            },
        );
        self.pending_changes.push(change);
    }

    /// Handles loading pages, navigation, and granting access to `Paint`.
    #[servo_tracing::instrument(skip_all)]
    fn handle_request(&mut self) {
        #[expect(clippy::large_enum_variant)]