Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hot reload in 2.0.0-canary-10/11: elements inserted with JavaScript disappear on reload #32

Closed
AleksandrHovhannisyan opened this issue Jun 16, 2022 · 4 comments
Labels
bug Something isn't working
Milestone

Comments

@AleksandrHovhannisyan
Copy link

AleksandrHovhannisyan commented Jun 16, 2022

Describe the bug

I've been test running 2.0.0-canary-10 for a few weeks now on my blog. So far, I'm a BIG fan of the new reload behavior! It makes authoring a much more pleasant experience and is so much faster. That said, I did notice a bug where the hot reload breaks and elements inserted into the page with JavaScript disappear once the hot reload occurs.

Suppose you have this index.html in an absolute bare-minimum 11ty project with nothing else:

<p>I love <span id="test"></span></p>
<script>
document.getElementById('test').innerText = '11ty';
</script>

On an initial page load or a manual reload, it works as expected: The user sees I love 11ty.

If you later edit the file and save it to trigger a rebuild, though, the page reloads and the JavaScript breaks. Now, you only see I love.

To Reproduce
Steps to reproduce the behavior:

  1. Clone https://github.com/AleksandrHovhannisyan/11ty-sandbox/tree/2.0.0-canary-11-js-hotreload.
  2. Run yarn to install dependencies.
  3. Run yarn serve to start the dev server.
  4. Navigate to localhost:8080. Observe the page reads: I love 11ty.
  5. Open, edit, and save src/index.html.
  6. Observe that the server hot-reloads the page.
  7. Observe that the paragraph now reads I love.

Expected behavior
This is somewhat expected because the page didn't actually reload, so the JavaScript doesn't re-run. On the other hand, if the page isn't actually reloading, elements previously inserted by JavaScript should be preserved. It can be a little annoying if you're writing JavaScript and want to see the results since you need to reload the page manually on each refresh. However, so far this has only been a minor annoyance for me.

Screenshots

N/A

Environment:

  • OS and Version: N/A (Windows 10 build 19044,1706, running 11ty in WSL 2)
  • Eleventy Version: 2.0.0-canary-11 (also reproducible in 10)
@zachleat zachleat transferred this issue from 11ty/eleventy Jun 17, 2022
@zachleat zachleat added bug Something isn't working and removed needs-triage labels Jun 17, 2022
@zachleat
Copy link
Member

zachleat commented Jun 17, 2022

Yeah, we might need to think a little bigger here. Similar concerns were reported by @j-f1 at #7 too!

@zachleat zachleat added this to the v1.0.0 milestone Jun 17, 2022
@zachleat
Copy link
Member

Found this excellent helper which seems to work well to rerun scripts

patrick-steele-idem/morphdom#178 (comment)

@zachleat
Copy link
Member

Shipping with 1.0.0-canary.10

@AleksandrHovhannisyan
Copy link
Author

Wow, that was quick! Thanks @zachleat!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants