Skip to content
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

[BUG] Aria Blocking UI #2688

Open
jolevesq opened this issue Jan 15, 2025 · 0 comments
Open

[BUG] Aria Blocking UI #2688

jolevesq opened this issue Jan 15, 2025 · 0 comments

Comments

@jolevesq
Copy link
Member

jolevesq commented Jan 15, 2025

We have error in the console

Blocked aria-hidden on an element because its descendant retained focus. The focus must not be hidden from assistive technology users. Avoid using aria-hidden on a focused element or its ancestor. Consider using the inert attribute instead, which will also prevent focus. For more details, see the aria-hidden section of the WAI-ARIA specification at https://w3c.github.io/aria/#aria-hidden.
Element with focus: button
Ancestor with aria-hidden:  

This error comes from the geoview-renderer, look for // TODO: Performance #2688

INFO

The aria-blocking error in the web console is likely occurring because the processStyle function is performing synchronous operations that could block the main thread. Looking at the open file, we can see this is happening in the style processing for geometry rendering.

Here's how to fix it: [1]

/** 
 * Gets and creates feature style asynchronously to prevent main thread blocking
 * @async
 */
export async function getAndCreateFeatureStyle(
  feature: FeatureLike,
  style: TypeLayerStyleConfig,
  label: string,
  filterEquation?: FilterNodeArrayType,
  legendFilterIsOff?: boolean,
  callbackWhenCreatingStyle?: (geometryType: TypeStyleGeometry, style: TypeLayerStyleConfigInfo) => void
): Promise<Style | undefined> {
  // Get the geometry type
  const geometryType = getGeometryType(feature);

  // The style to work on
  let styleWorkOn = style;

  // If style does not exist for the geometryType, create it.
  if (!style || !style[geometryType]) {
    const styleConfig = createDefaultStyle(geometryType, label);
    if (styleConfig) {
      if (style) styleWorkOn[geometryType] = styleConfig;
      else styleWorkOn = { [geometryType]: styleConfig };
      callbackWhenCreatingStyle?.(geometryType, styleConfig.info[0]);
    }
  }

  // Process style asynchronously
  if (styleWorkOn![geometryType]) {
    const styleSettings = style![geometryType]!;
    const { type } = styleSettings;
    
    // Wrap the style processing in a Promise to prevent blocking
    return new Promise((resolve) => {
      // Use requestAnimationFrame to process style during next frame
      requestAnimationFrame(() => {
        const processedStyle = processStyle[type][geometryType].call(
          '',
          styleSettings,
          feature as Feature,
          filterEquation,
          legendFilterIsOff
        );
        resolve(processedStyle);
      });
    });
  }
  
  return undefined;
}

// Update the calling code to handle the async nature:
async function updateFeatureStyle() {
  try {
    const style = await getAndCreateFeatureStyle(
      feature,
      styleConfig,
      label,
      filterEquation,
      legendFilterIsOff
    );
    // Use the style...
  } catch (error) {
    logger.logError('Error processing style', error);
  }
}

Key changes:

  • Made getAndCreateFeatureStyle async
  • Wrapped style processing in a Promise
  • Used requestAnimationFrame to schedule style processing
  • Added error handling
  • Updated function signature to reflect async nature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant