Consider the following scenario:
A is working on a problem X and has unpublished new material. A is then asked to review a paper: upon reading the abstract, A realizes that the authors are also working on problem X and appear to have duplicated some of A's unpublished material (the results - not clear from the abstract if the approach is also duplicated).
A now has four possibilities:
- decline to review the paper, or review it
- stop working on X, or continue to work on it
The safest combination might be to (decline to review, and stop working), but would it also be legitimate to (decline to review, and continue working) ?
The only problematic situtation seems to me to agree to review the paper, give it a deliberately bad review so it is rejected and then publish the own results. I personally would not review the paper in question at all because it might turn out that it is legitimate to reject it, and then it would be difficult to continue working independently.
Whether you should stop working on the problem is a more difficult question. In general I would say no unless it's something very specific with limited scope for further work. If you are reasonably sure that your work would go beyond what the other authors have done, there's no reason not to do it. You could always wait to see if the paper is published and if it is contact the authors and propose to work together.