I am new to lua modding, but my guess to the issue is that when [on_player_inventory_changed] gets called and you have a filtered slot in the quickbar that is partially filled, the function [transfer_stack(from,to)] tries to fill that slot by calling [to.transfer_stack(from)].
[to.transfer_stack(from)] would try to move every item in every nonempty slot in the inventory into the filtered slot, and registers [on_player_quickbar_inventory_changed] and [on_player_main_inventory_changed], both of which calls [on_player_inventory_changed].
But if you have no more of the item in the inventory to fill the filtered slot, [to.transfer_stack(from)] will just keep trying to move item A into the slot filtered with item B, and it would not be successful, and you would be stuck in a loop calling [on_player_inventory_changed] over and over.
I think my fix works by adding a check to stop calling [to.transfer_stack(from)] to try to move item A into a slot filtered with item B, so the game won't fall in the loop.