Skip to content

fix: allow autoConfig callbacks without global options - #529

Open
lprnmns wants to merge 1 commit into
fastify:mainfrom
lprnmns:fix/autoconfig-without-global-options-human-dco
Open

fix: allow autoConfig callbacks without global options#529
lprnmns wants to merge 1 commit into
fastify:mainfrom
lprnmns:fix/autoconfig-without-global-options-human-dco

Conversation

@lprnmns

@lprnmns lprnmns commented Aug 31, 2026

Copy link
Copy Markdown

Problem

When an autoloaded plugin exports a function-valued autoConfig and the autoload call omits the optional global options object, registration throws TypeError: Cannot read properties of undefined (reading 'prefix'). The documented callback configuration therefore cannot load unless callers provide an otherwise unnecessary empty options object.

Fix

Default the internal override configuration to an empty object before the callback result is merged. Explicit global options and the existing prefix precedence remain unchanged.

Tests

  • node --test --test-name-pattern='loads a plugin when the global options object is omitted' test/commonjs/auto-config-no-global.js — failed before the fix with the expected TypeError; passed after the fix
  • npm test — passed; borp reported 275 passed, 0 failed, and 100% coverage
  • npm run lint — passed
  • node --check index.js && node --check test/commonjs/auto-config-no-global.js && node --check test/commonjs/auto-config-no-global/route.js — passed
  • git diff --check HEAD^ HEAD — passed

Compatibility

This changes only the previously failing callback-only configuration. Calls that provide global options retain their existing merge and prefix behavior; no public type, dependency, or package-version change is included.

Related issue

Independent reproduction; no linked issue. Function-valued autoConfig support was previously introduced by historical PR #381.

Signed-off-by: lprnmns <manasalperen@gmail.com>
@lprnmns
lprnmns marked this pull request as ready for review August 31, 2026 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant