document.writeln vs console.log
bencooling opened this issue · comments
Thanks @ahfarmer for your posts and repos.
You mention in the source code
// console.log statements are reprinted on every reload.
Can you explain if I replace console.log with document.writeln it doesn't reload?
Hmmm, I don't think document.writeln
will work with HMR.
document.writeln
doesn't work after the document is finished writing. HMR works by updating JavaScript without a reload, which means the document will always be finished loading.
I think this StackOverflow post might help.
You probably want something like browserSync. It will reload the entire webpage whenever you make changes.
An even better option would be to abandon document.writeln
in favor of DOM manipulations like createElement and appendChild.
👍🏼Legend thanks heaps. I didn't particularly need document.writeln
but it tripped me up as I thought I didn't have HMR working until I finally decided to use a console.log after reading over your source code. Thanks again.