@syphdias Right, reading the heredoc is fully handled by the shell. For bash that would be using readline, for zsh it is zle. The shell writes the input to a temporary file [1] and therefore passing that as input to a command works just like any other redirection.
The important difference is that the shell uses the tty in non-canonical mode and handles the editing itself. The shell changes the tty settings for the prompt and restores them (to canonical mode) when a process runs that is directly attached to the tty. Therefore, when the shell is reading the input, is not the kernel tty driver that has to handle special characters for editing, which would have the line length limit of 4096 characters.
[1] As I looked it up now, bash >= 5.1 actually has an optimization to use a pipe(2) if the heredoc input fits in there without blocking. Otherwise it falls back to the temporary file. I assume zsh might do something similar. https://cgit.git.savannah.gnu.org/cgit/bash.git/tree/redir.c?h=bash-5.3#n419