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

fix(2767): prevent calling onRoute while prefixing #2782

Merged
merged 7 commits into from
Jan 13, 2021

Conversation

salmanm
Copy link
Member

@salmanm salmanm commented Jan 8, 2021

Alternative fix for #2767

Approach explained in #2767 (comment)

Checklist

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

@salmanm
Copy link
Member Author

salmanm commented Jan 8, 2021

Sorry the link doesn't seem to be taking me to a line I could relate your comment to.
What do you think we should skip?

Copy link
Member

@RafaelGSS RafaelGSS left a comment

Choose a reason for hiding this comment

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

I would recommend documenting this property here.

I also would like to add a note inside ignoreTrallingSlash documentation about this behavior under the hood.

test/hooks.test.js Show resolved Hide resolved
@mcollina
Copy link
Member

mcollina commented Jan 8, 2021

Sorry the link doesn't seem to be taking me to a line I could relate your comment to.
What do you think we should skip?

fastify/lib/route.js

Lines 200 to 207 in b8122e2

for (const hook of this[kHooks].onRoute) {
try {
hook.call(this, opts)
} catch (error) {
done(error)
return
}
}

@salmanm
Copy link
Member Author

salmanm commented Jan 8, 2021

I see, so we don't call the onRoute hook twice in the first place. Makes sense. Updated the PR.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina
Copy link
Member

mcollina commented Jan 9, 2021

Do you think this is semver-major or could we ship it in v3?

@salmanm
Copy link
Member Author

salmanm commented Jan 9, 2021

This didn't cause any existing tests to change also the behavior isn't a documented or even expected one. So I'd not think of it as a semver-major.

test/hooks.test.js Show resolved Hide resolved
Copy link
Member

@jsumners jsumners left a comment

Choose a reason for hiding this comment

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

Do I understand this correctly? This PR adjust the internal API of route registration to pass around a new internal options object that does not mutate the user provided options object. This new internal object gets decorated with additional metadata about what sort of actions are being performed around route registration.

@salmanm
Copy link
Member Author

salmanm commented Jan 11, 2021

@jsumners This PR does not change user provided options, neither we used to. Adding an extra metadata was my initial proposal before Matteo suggested we could skip triggering onRoute hook altogether while prefixing, which makes sense.

So right now, this PR only makes it skip calling onRoute for /foo/ when it already has triggered it for /foo.

lib/route.js Show resolved Hide resolved
lib/route.js Outdated Show resolved Hide resolved
@salmanm salmanm changed the title fix(2767): allow detecting when onRoute is being called for prefixing fix(2767): prevent calling onRoute while prefixing Jan 11, 2021
Copy link
Member

@Eomm Eomm left a comment

Choose a reason for hiding this comment

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

I agree to release it as semver-patch since the route object was the same 👍

lib/route.js Outdated Show resolved Hide resolved
Copy link
Member

@RafaelGSS RafaelGSS left a comment

Choose a reason for hiding this comment

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

LGTM.

lib/route.js Outdated Show resolved Hide resolved
lib/route.js Outdated Show resolved Hide resolved
lib/route.js Outdated Show resolved Hide resolved
lib/route.js Outdated Show resolved Hide resolved
Copy link
Member

@jsumners jsumners left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@delvedor delvedor left a comment

Choose a reason for hiding this comment

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

LGTM

@delvedor delvedor added bugfix Issue or PR that should land as semver patch v3.x Issue or pr related to Fastify v3 labels Jan 13, 2021
@mcollina mcollina merged commit 5a6aa29 into fastify:master Jan 13, 2021
@salmanm salmanm deleted the fix-2767 branch January 14, 2021 11:02
@github-actions
Copy link

github-actions bot commented Feb 4, 2022

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bugfix Issue or PR that should land as semver patch v3.x Issue or pr related to Fastify v3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants