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

this again? #1496

Closed
Polymorphe57 opened this issue Jul 26, 2023 · 2 comments
Closed

this again? #1496

Polymorphe57 opened this issue Jul 26, 2023 · 2 comments

Comments

@Polymorphe57
Copy link
Contributor

A subtility with this:

Click on "Update 2" brings an error "Uncaught RangeError: Maximum call stack size exceeded"

see in playground

@ged-odoo
Copy link
Contributor

linked to #1317

@sdegueldre
Copy link
Contributor

sdegueldre commented Jul 26, 2023

Behaves as expected: unqualified names are looked up on the context meaning that calling functions directly inside of templates (instead of calling them as a method on this) causes them to be bound to the rendering context, causing the code to be essentially equivalent to

const renderingContext = {
  update() {
    return this.update();
  }
}

In general, it's advisable to never call functions using their unqualified names in templates as they will be implicitly bound to the rendering context:

<div t-on-click="() => method()"/> <!-- incorrect -->
<div t-on-click="() => this.method()"/> <!-- correct -->
<div t-on-click="() => props.method()"/> <!-- correct -->
<div t-on-click="() => this.props.method()"/> <!-- correct but needlessly qualified: the method will be bound to props in both cases -->

Hopefully this can help people who stumble upon this issue in the future. We will address this issue in owl 3 (for which we have no timeline as of yet)

@sdegueldre sdegueldre closed this as not planned Won't fix, can't repro, duplicate, stale Jul 26, 2023
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

No branches or pull requests

3 participants