Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

"Please apply 'observer' before applying 'inject'" should be an error not a warning #808

Closed
clehene opened this issue Dec 9, 2019 · 8 comments
Labels

Comments

@clehene
Copy link

clehene commented Dec 9, 2019

Note that I added a PR to update pitfalls.ms mobxjs/mobx#2226
However, I think this is not visible enough. This should throw an exception, unless there's a legitimate use-case to not do it. I spent several hours debugging babel to understand why react doens't re-render on observable changes.

You are trying to use 'observer' on a component that already has 'inject'. Please apply 'observer' before applying 'inject'

@danielkcz danielkcz transferred this issue from mobxjs/mobx Dec 9, 2019
@danielkcz
Copy link
Contributor

danielkcz commented Dec 9, 2019

You are right an exception would be probably more visible, not sure what was the reasoning for the warning. Let's discuss it.

"Mobx observer: You are trying to use 'observer' on a component that already has 'inject'. Please apply 'observer' before applying 'inject'"

I suppose we could show a component name and the isMobxInjector could be carrying the component name as well instead of just a boolean flag.

cc @mweststrate @xaviergonz @vkrol

@danielkcz
Copy link
Contributor

@clehene Just in case you have missed it, but we are slowly moving away from inject pattern. It won't be removed anytime soon, but if you are writing some new-ish code, consider migrating away from it.

https://mobx-react.js.org/recipes-migration

@clehene

This comment has been minimized.

@danielkcz

This comment has been minimized.

@danielkcz
Copy link
Contributor

@clehene Given that you seem to be the only one bothered by this problem, let's leave it like this unless you are willing to work on the PR. It's probably not worth the effort due to obsolete pattern.

@clehene
Copy link
Author

clehene commented Apr 24, 2020

@FredyC hey - is a throw instead of console.warn ok? I think it affects more than myself once :) (we're also moving away towards contexts). If that's the only change, I'll make a quick PR

@danielkcz
Copy link
Contributor

Yea, that should be enough, along with tweaking tests I would expect.

@lock
Copy link

lock bot commented Jun 24, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or questions.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants