Does not work if script loads before markup
Closed this issue · 2 comments
Describe the bug
If the script is loaded before the DOM is loaded, for each new storage-form
tag the forms
method will return nothing (since those DOM elements aren't in the tree yet), and the event handler will not be added. It works fine if you load the script after the DOM is loaded, but that's not clear in the documentation, and later additions to the page won't work as expected.
To Reproduce
Steps to reproduce the behaviour:
- Add the script link in the
<head/>
(I know this isn't best practice) - Add the theme-switcher example into the
<body/>
- Load the page
- See that the form does not persist
Expected behaviour
The form should persist
Desktop (please complete the following information):
- OS: MacOS Sonoma
- Browser Safari
- Version 17.2.1
Additional context
I'm using the unpkg link in dev on a static webpage, loaded via file:/// URLs
Could you provide a demo @TALlama? Just a little confused which script is being loaded in the <head>
. The demo in the project has the storage-form
script loaded in the head and that does appear to work: https://daviddarnes.github.io/storage-form/demo.html
Closing this for now, will reopen once further explanation/example is provided