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

no-this-assign-in-render: Only fail if the assignment is to a reactive property #214

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

bearfriend
Copy link

Alternative/addition to #213

  • Walk the assignment tree looking for true this assignments only
  • Compare first assignment member against declared reactive properties, failing only on match
  • Add and modify tests for property comparisons

@bearfriend
Copy link
Author

I don't work with a lot of this (including typescript) often, so suggestions and edits are welcome.

}

if (propertyMap.has(propertyName) ||
parent.property.type === 'Identifier' && parent.computed) {
Copy link
Author

Choose a reason for hiding this comment

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

There doesn't seem to be a great way to get the computed value (i.e. x in this[x]) to compare against the properties, so we fail on this as well.

@bearfriend bearfriend force-pushed the dgleckler/no-this-assign-in-render-reactive-properties branch from a604e2d to d8f4313 Compare September 11, 2024 20:39
@bearfriend
Copy link
Author

@43081j Can you have a look at this when you get a chance?

@bearfriend
Copy link
Author

@43081j Any interest in moving this along?

@43081j
Copy link
Owner

43081j commented Oct 25, 2024

Sorry I've been quite busy traveling recently. I'll try get to this in the next few days 👍

@43081j
Copy link
Owner

43081j commented Oct 27, 2024

the render method of a lit element is really meant to be a 'pure' function, in that it will produce the same result with the same props/state every time

this does mean you're technically correct that we care most about reactive properties. but, really, I think we shouldn't be mutating this at all during render and should use the lifecycle callbacks instead

@justinfagnani do you have thoughts on this?

I think we should just fix the existing behaviour instead of constraining it to reactive properties.

Justin can confirm but I feel like render just shouldn't mutate at all, really (of this at least)

as far as I understand, you need this because we're incorrectly flagging things like foo(this).bar = 123 as a mutation of this. that is a bug and we should fix it for sure

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