Skip to content

[BUGFIX] plain method calling from templates (no explicit binding required -- follows JS semantics) - on still requires binding - #21469

Draft
NullVoxPopuli wants to merge 1 commit into
mainfrom
nvp/fix-this-binding-for-real
Draft

NullVoxPopuli wants to merge 1 commit into
mainfrom
nvp/fix-this-binding-for-real

Conversation

@NullVoxPopuli

@NullVoxPopuli NullVoxPopuli commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

supersedes

this PR enables/unblocks the change in recommendation RFC:

Notes

we can't tie this-fixes to invokeHelper, because a helper manager's return value is from getValue, which only receives the args and definition from createHelper, so like.. 😬

as in, the helper manager pattern is what is screwing us over here, because we (correctly?) abstracted references away from public API, but the reference is what is needed to invoke functions.

So, now the path forward I see is to... not use a helper a manager for the "default helper manager" case, and wire it all up using only private apis, no manager

I think the best I con do is bind the definition before createHelper (only for the default case)


Main test cases I care about:

  • calling methods from classes (such as in a class component)
  • calling methods on chained property paths (could be class or plain object)

Things we didn't fix (because these are problems with JavaScript)

  • function references passed to on (addEventListener)
  • function references passed anywhere else

REPL PR: NullVoxPopuli/limber#2170
Deployed: https://test-ember-source-nvp-fix-th.limber-glimdown.pages.dev/
Demo: https://test-ember-source-nvp-fix-th.limber-glimdown.pages.dev/edit?c=JYWwDg9gTgLgBAYQuCA7Apq%2BAzKy4DkAAgOYA2oI6UA9AMbKQZYEDcAUKJLHAN5wwoAQzoBrdABM4AXzi58xcpWo1BI0cFQk27dugAe3eBPTYhAVzLw6ZIQGc7cABLoyZCAHVoZKQZiYJRyQUZnhedjg4IjUxSTgGcyw4AF44AAYOCLgaGjgodABHc2B8qRgIOAAjdDghKDwAdzg7GGA3LM06fKok1IAKAEoUgD4%2BLMiYAAtgOwA6BKSAalSARg5I2V1IiQhzSrJJQbHIyPyYcyhUAWm5hfgAKjgAJnWZLbgAHn9wW39h8c%2BYGGAE1dnBJkIAG41GzAWJlSY1SrmGDlK68XhTGbzXZYaSyVpUOYfGhAgEfIFCVBSHZ7A4SABcfExN1mtP2knxJLJ5ORqLQAgAnmB0MkAER8tFi5kCsWwsTSrFzTrdTAwfHDBAUMQkyVof6REnfMC-dD-aTsIA&format=gjs

assert.equal(this.stashedFn(), 'arg1: foo, arg2: bar');
}

'@test there is no `this` context within the callback'(assert) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

a change in behavior, but for the better -- I dare say: a bugfix

@github-actions

github-actions Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

📊 Size report

Tarball size — 1.2 MB → 1.2 MB

dist/dev   0.1%↑

File Before (Size / Brotli) After (Size / Brotli)
./packages/shared-chunks/args-{hash}.js 5.2 kB / 1.4 kB 5%↑5.5 kB / 6%↑1.4 kB
./packages/shared-chunks/index-{hash}.js 62.6 kB / 12.5 kB 2%↑63.7 kB / 3%↑12.9 kB
./packages/shared-chunks/program-{hash}.js 5 kB / 1.4 kB 3%↑5.2 kB / 5%↑1.5 kB
./packages/shared-chunks/render-{hash}.js 56.1 kB / 12.2 kB 0.5%↑56.4 kB / 1%↑12.3 kB
Total (Includes all files) 2.1 MB / 493.5 kB 0.1%↑2.1 MB / 0.2%↑494.3 kB

dist/prod   0.1%↑

File Before (Size / Brotli) After (Size / Brotli)
./packages/shared-chunks/api-{hash}.js 25.8 kB / 5.8 kB -75.5%↓6.3 kB / -71.9%↓1.6 kB
./packages/shared-chunks/args-{hash}.js 4 kB / 973 B 6%↑4.3 kB / 9%↑1.1 kB
./packages/shared-chunks/index-{hash}.js 59.8 kB / 12.1 kB 2%↑61 kB / 3%↑12.4 kB
./packages/shared-chunks/program-{hash}.js 5 kB / 1.4 kB 3%↑5.2 kB / 5%↑1.5 kB
./packages/shared-chunks/render-{hash}.js 52.4 kB / 11.3 kB 0.6%↑52.7 kB / 1%↑11.5 kB
Total (Includes all files) 1.9 MB / 450.8 kB 0.1%↑1.9 MB / 0.2%↑451.7 kB

smoke-tests/v2-app-template/dist   0.1%↑

File Before (Size / Brotli) After (Size / Brotli)
./assets/api-{hash}.js 290.8 kB / 78.1 kB 0.1%↑291.1 kB / 0.2%↑78.2 kB
Total (Includes all files) 343.1 kB / 95.2 kB 0.1%↑343.4 kB / 0.1%↑95.3 kB

smoke-tests/v2-app-hello-world-template/dist   0.2%↑

File Before (Size / Brotli) After (Size / Brotli)
./assets/main-{hash}.js 134.4 kB / 37.6 kB 0.2%↑134.7 kB / 0.1%↑37.6 kB
Total (Includes all files) 134.7 kB / 37.7 kB 0.2%↑135 kB / 0.2%↑37.8 kB

🤖 This report was automatically generated by wyvox/pkg-size

@NullVoxPopuli NullVoxPopuli changed the title fix plain method calling [BUGFIX] enable plain method calling from templates Jun 12, 2026
@NullVoxPopuli NullVoxPopuli changed the title [BUGFIX] enable plain method calling from templates [BUGFIX] enable plain method calling from templates (no explicit binding required -- follows JS semantics) Jun 12, 2026
@NullVoxPopuli
NullVoxPopuli marked this pull request as ready for review June 12, 2026 20:35

// eslint-disable-next-line @typescript-eslint/no-unsafe-return -- @fixme
return (fn as AnyFn).call(context, ...args, ...invocationArgs);
return (fn as AnyFn).call(self, ...args, ...invocationArgs);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the actual fix is here

* The reference this one was created from via a property read (`parent.path`),
* if any. See {@linkcode parentRefFor}.
*/
public parent: Nullable<Reference> = null;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

more reference linking 🙈

Comment thread packages/@ember/-internals/glimmer/tests/integration/this-binding-test.gjs Outdated
@NullVoxPopuli

Copy link
Copy Markdown
Contributor Author

from review times -- this PR needs to be re-worked to only solve {{ (ctx.called) }}

@NullVoxPopuli
NullVoxPopuli marked this pull request as draft June 16, 2026 18:24
@NullVoxPopuli
NullVoxPopuli force-pushed the nvp/fix-this-binding-for-real branch from f25e012 to 889278b Compare June 16, 2026 20:53
@NullVoxPopuli NullVoxPopuli changed the title [BUGFIX] enable plain method calling from templates (no explicit binding required -- follows JS semantics) [BUGFIX] plain method calling from templates (no explicit binding required -- follows JS semantics) - on still requires binding Jun 16, 2026
@NullVoxPopuli
NullVoxPopuli force-pushed the nvp/fix-this-binding-for-real branch 2 times, most recently from 4b573d6 to 9c29b51 Compare June 16, 2026 21:44
@NullVoxPopuli
NullVoxPopuli marked this pull request as ready for review June 16, 2026 22:11
@NullVoxPopuli
NullVoxPopuli requested a review from ef4 June 26, 2026 04:24
associateDestroyableChild(helperInstanceRef, helperRef);
} else if (isIndexable(definition)) {
let helper = resolveHelper(definition, ref);
let helper = resolveHelper(bindFunctionToParent(definition, ref), ref);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

TODO: move to invokeHelper

@NullVoxPopuli
NullVoxPopuli force-pushed the nvp/fix-this-binding-for-real branch from 9c29b51 to 31130d8 Compare June 30, 2026 19:16
@NullVoxPopuli
NullVoxPopuli marked this pull request as draft June 30, 2026 19:17
@NullVoxPopuli

This comment was marked as outdated.

@NullVoxPopuli

This comment was marked as outdated.

@NullVoxPopuli
NullVoxPopuli force-pushed the nvp/fix-this-binding-for-real branch from 9e08c07 to ad343b4 Compare September 1, 2026 13:49

This branch has not been deployed

No deployments
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.

2 participants