The view is not filtering the duplicate nodes i have a view which is not filtering the duplicated nodes and i tried couple of solutions but it looks like they are not working. 

The code I am using is the following.

function mymodule_views_pre_render(ViewExecutable $view) {
  if ($view-&gt;id() == 'basicnews') {
    $unique_nids = $new_results = array();

    // Loop through results and filter out duplicate results.
    foreach ($view-&gt;result as $index =&gt; $result) {
      if (!in_array($result-&gt;nid, $unique_nids)) {
        $unique_nids[] = $result-&gt;nid; 
        $new_results[] = $result;
      }

      // Replace $view-&gt;result with new array. Apparently views requires sequentially keyed
      // array of results instead of skipping keys (e.g. 0, 2, 4, etc), so we can't just
      // unset the duplicates.
      $view-&gt;result = $new_results;
    }
  }
}


Is there any patch or work-around for this issue?
You can handle most duplicate node issues using Views Aggregation options.

Go to advanced in the view and select "Use Aggregation"

Then in the fields area, set the aggregation settings.  Generally, you just want the group together option with Entity ID as the group column.  Sometimes you have to play around with other settings as well.