Skip to content

fix: point this to parent at onRegister#5675

Merged
mcollina merged 6 commits into
fastify:mainfrom
gurgunday:bind-onregister
Oct 15, 2024
Merged

fix: point this to parent at onRegister#5675
mcollina merged 6 commits into
fastify:mainfrom
gurgunday:bind-onregister

Conversation

@gurgunday

@gurgunday gurgunday commented Sep 9, 2024

Copy link
Copy Markdown
Member

For #4967

To onRegister hooks we pass this and the instance, however there are 2 problems:

  1. what this points to is documented neither in types nor the docs
  2. the goal was probably to pass the parent, as the other passed parameter, instance, is the new fastify instance, but this actually points to the avvio instance as can be seen from here:

avvio.override = override

This PR passes the parent as this

For more info, see: #5670 (comment)

@github-actions github-actions Bot added the typescript TypeScript related label Sep 9, 2024
@gurgunday gurgunday requested review from a team and Eomm September 9, 2024 14:33
@gurgunday

gurgunday commented Sep 9, 2024

Copy link
Copy Markdown
Member Author

citgm errors are irrelevant, it's not breaking any core plugins

@gurgunday

Copy link
Copy Markdown
Member Author

@mcollina if there is a bug here (this being avvio instead of the parent instance and not being documented in types), we should fix it before v5 I think

@Eomm Eomm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what this points to is documented neither in types nor the docs

I created a task here #4967 to remind that.

Binding this to old seems reasonable because we are saying: this is the object that called the register method, and this statement is equally true for the other hooks.

I must underline that this PR is a step forward, but if I'm not wrong, to close the issue we apply the
boundThisAndParamsObject.call(instance, { options, instance }) interface as shared here: #4967 (comment)

@gurgunday

gurgunday commented Sep 14, 2024

Copy link
Copy Markdown
Member Author

Just for context, for v5, Matteo pointed out it’s too late to make a big breaking change, so I think we’ll defer the parameter change to v6, but we should at least have consistent this bindings in v5, and luckily this one doesn’t seem to break any plugins and achieves that - probably because it wasn’t even documented

Comment thread lib/pluginOverride.js

@Uzlopak Uzlopak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

RSLGTM

Makes actually sense, i guess

@gurgunday gurgunday added the semver-major Issue or PR that should land as semver major label Sep 19, 2024

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina merged commit 3affc34 into fastify:main Oct 15, 2024
@gurgunday gurgunday deleted the bind-onregister branch October 15, 2024 20:57
@github-actions

Copy link
Copy Markdown

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 Oct 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

citgm-core-plugins semver-major Issue or PR that should land as semver major typescript TypeScript related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants