According to the WHATWG html spec, you seem to be commenting properly. It doesn't seem to explicitly say that Comment nodes (which is what you're actually creating when you write comments) cannot be adjacent to Element nodes. I've tried to replicate your problems, but I wasn't successful. Maybe you have some sort of repl?
Can you post it into a Repl? I'm inclined to agree with Vandesm14, just based on what I see here.