Skip to content

Deprecate unbound method usage#299

Open
jonkoops wants to merge 1 commit intokeycloak:mainfrom
jonkoops:deprecate-unbound-methods
Open

Deprecate unbound method usage#299
jonkoops wants to merge 1 commit intokeycloak:mainfrom
jonkoops:deprecate-unbound-methods

Conversation

@jonkoops
Copy link
Copy Markdown
Contributor

@jonkoops jonkoops commented Apr 22, 2026

This PR converts public arrow function class fields on the Keycloak class back to regular prototype methods and introduces a deprecatedBoundMethods helper that wraps them in the constructor for backwards compatibility.

When a method is called with a lost this context (e.g. via destructuring like const { login } = keycloak; login()), a per-method deprecation warning is emitted once in the console. The methods continue to work correctly in the meantime. In the next major version, the wrappers will be removed and unbound calls will fail, which is the standard behavior for class methods.

The arrow function class fields were introduced in #204 to fix destructuring, but they come with downsides: no prototype sharing (increased memory per instance), no reference equality across instances, and broken subclassing. This change restores proper prototype methods while giving consumers time to migrate away from destructuring patterns.

Closes #300

@jonkoops jonkoops force-pushed the deprecate-unbound-methods branch 4 times, most recently from b3c71f9 to ed03667 Compare April 23, 2026 13:08
@jonkoops jonkoops changed the title Deprecate unbound method usage on Keycloak Deprecate unbound method usage Apr 23, 2026
Convert public arrow function class fields back to regular prototype
methods and wrap them with `deprecatedBoundMethods` in the constructor
for backwards compatibility.

When a method is called with a lost `this` (e.g. via destructuring),
a per-method deprecation warning is emitted once. In the next major
the wrappers will be removed and unbound calls will fail.

Closes keycloak#300

Signed-off-by: Jon Koops <[email protected]>
@jonkoops jonkoops force-pushed the deprecate-unbound-methods branch from ed03667 to 1d0e84c Compare April 23, 2026 13:09
@jonkoops jonkoops marked this pull request as ready for review April 23, 2026 13:12
@jonkoops jonkoops requested review from pskopek and rmartinc April 23, 2026 13:12
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.

Deprecate unbound method usage

1 participant