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

Stop establishing unnecessary reactive dependencies #406

Merged
merged 2 commits into from
Mar 31, 2023
Merged

Stop establishing unnecessary reactive dependencies #406

merged 2 commits into from
Mar 31, 2023

Conversation

imajus
Copy link
Contributor

@imajus imajus commented Mar 3, 2023

The problem I have faced in my current Meteor project is clearly demonstrated in this simple example project: https://github.com/imajus/blaze-reactive-loop-example

While this doesn't cause visible issues in most cases, in some cases, like the one presented in this repository, it can lead to unexpected and hard-to-track issues. Additionally, it adds unnecessary overhead to the reactive computation system, which may result in unnecessary re-rendering.

Proposed solution

Since the behavior in question is definitely not intended and potentially harmful, I believe the best approach would be to prevent event handlers from establishing new reactive dependencies if they are called from any reactive computation.

@CLAassistant
Copy link

CLAassistant commented Mar 3, 2023

CLA assistant check
All committers have signed the CLA.

@jankapunkt
Copy link
Collaborator

@imajus thank you for this PR! Would you mind checking the tests? There seem to be at least one failed test, indicating that this may be a breaking change.

@imajus
Copy link
Contributor Author

imajus commented Mar 3, 2023

@jankapunkt thanks for a guidance. There was, in fact, an error in my initial implementation, which is now fixed. Hail to the automated testing!

@jankapunkt
Copy link
Collaborator

Generally approved from my end. @StorytellerCZ do you have something to add? If not we can merge this. @imajus is there a way to test this from a UnitTest perspective? I've looked into the the example and I would like to avoid detecting, whether we are in a loop (if it fails it would consume all our free CI time).

Copy link
Collaborator

@StorytellerCZ StorytellerCZ left a comment

Choose a reason for hiding this comment

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

LGTM

@imajus
Copy link
Contributor Author

imajus commented Mar 22, 2023

@jankapunkt Thanks for approving the PR.
For the automated test you may choose to merge the following PR to this branch first, which will make currently failing test there to pass, and only then merge this PR.

What I have introduced there is more like an integration test, but it is designed the way that it won't cause an infinite loop in case of a failure. I think that it is the most practical way of testing this issue.

If you'd like I could also cover Template.events with unit tests, ensuring that no reactive dependencies are established in the event handler wrappers there. I just need a confirmation that such test would make sense in the system.

@jankapunkt
Copy link
Collaborator

@StorytellerCZ should we target 2.6.2 or 3.0.0 with this?

@StorytellerCZ StorytellerCZ added this to the Blaze 2.6.2 milestone Mar 29, 2023
@StorytellerCZ
Copy link
Collaborator

Let's do 2.6.2 and release it with the changes earlier.

@StorytellerCZ StorytellerCZ changed the base branch from master to release-2.6.2 March 31, 2023 06:35
@StorytellerCZ StorytellerCZ merged commit 355b3bc into meteor:release-2.6.2 Mar 31, 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

Successfully merging this pull request may close these issues.

4 participants