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

Resolve dirNameRoutePrefix interferes with auto-hooks #454

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

MrWook
Copy link
Contributor

@MrWook MrWook commented Mar 27, 2025

Should resolve #453

Previously the prefix from dirNameRoutePrefix was used as a key to build the plugins which resulted in an unexpected behaviour.
For example with:

fastify.register(pluginAutoload, {
  autoHooks: true,
  cascadeHooks: true,
  // ISSUE: The parent folder routes and the first-level child routes will inherit the last registered hook (e.g., third.hook.mjs).
  dirNameRoutePrefix: false,
})

The routes in the parent folder were using the child folder hooks and if you have multiple child folder in the parent folder all of them would be using the last registered hook see the issue.

I tested this in my reproduction repository and it seems to be working as expected now.

Copy link
Member

@jean-michelet jean-michelet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you plz write a test that proove the bug is fixed: not having hooks registered in children plugins when dirNameRoutePrefix === false or dirNameRoutePrefix === () => false..

You can write a test here, the folder should have the name of the issue.

@MrWook
Copy link
Contributor Author

MrWook commented Mar 28, 2025

I added tests and verified them against the previous implementation, which failed as I described earlier. These tests now effectively cover the issue.

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.

dirNameRoutePrefix interferes with auto-hooks
2 participants