If you change your ifif
statement to use $query->is_main_query()
like the example on the is_main_query()
codex page, does that resolve the issue?
The nav menus are created by a query, so usually this problem stems from the pre_get_postspre_get_posts
interfering with the menus query. Hence, I wonder whether that check isn't working.