It's the same distance that the server will close out a workbench or chest inventory if you're moved from it (by water or by being knocked back). I was going to rewrite this to check the distance from your opened inventory's location when being teleported and then closing it out if the teleport was greater than 8 blocks.