Skip to content

Infinite RPC reconnection loop when running behind reverse proxy (nginx) #243

@fabkho

Description

@fabkho

Environment

  • @nuxt/a11y version: 1.0.0-alpha.1
  • Nuxt version: 4.x
  • Reverse proxy: nginx (Laravel Valet)

Reproduction

  1. Run a Nuxt app with @nuxt/a11y behind a reverse proxy (nginx)
  2. Add the /__nuxt-a11y-client location block to nginx config
  3. Open DevTools and navigate to the a11y tab
  4. Observe the infinite reconnection loop in WebSocket messages and console

Describe the bug

Setup

I'm running a Nuxt app behind an nginx reverse proxy with a base path:

location /admin {
    proxy_pass http://127.0.0.1:8091;
    proxy_set_header X-Real-Ip $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

# Added for a11y module
location /__nuxt-a11y-client {
    proxy_pass http://127.0.0.1:8091;
    proxy_set_header X-Real-Ip $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

Without the added "location /__nuxt-a11y-client" it does not work at all cause this module does not set the baseUrl set in nuxt config. Other modules devtools just work btw. So maybe we should do that?

Problem

When I open the Nuxt DevTools and navigate to the a11y tab, the module enters an infinite reconnection loop. The WebSocket messages show nuxt-a11y-rpc:connected being called repeatedly with different IDs:

This causes:

  • Continuous scanning that never stops
  • Console logs repeating indefinitely
  • DevTools UI constantly reloading/refreshing

The loop stops when I switch to a different DevTools tab.

Possible cause

The onDevtoolsClientConnected callback in client/app/composables/rpc.ts appears to fire multiple times when the connection is unstable. Each call triggers nuxtA11yRpc.value!.connected() which sends nuxt-a11y:connected to the main app, triggering a new scan.

Temporary fix

Add a guard to prevent multiple connected() calls:

let hasConnected = false

onDevtoolsClientConnected(async (client) => {
  // ... setup code ...

  if (!hasConnected) {
    hasConnected = true
    try {
      await nuxtA11yRpc.value!.connected()
    } catch (error) {
      console.debug('[Nuxt A11y] Initial connection error (expected):', error)
    }
  }
})

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions