diff options
author | 2023-10-26 19:13:43 +0800 | |
---|---|---|
committer | 2023-10-26 19:13:43 +0800 | |
commit | ec7f53168273e040119341c8e3bbdf1571bccfa0 (patch) | |
tree | 1d00b81d6b9caadd5faf16bee28488f22dcb5002 /examples | |
parent | c8976440ff396843af5d73ddddd97b230a1866f5 (diff) | |
download | astro-ec7f53168273e040119341c8e3bbdf1571bccfa0.tar.gz astro-ec7f53168273e040119341c8e3bbdf1571bccfa0.tar.zst astro-ec7f53168273e040119341c8e3bbdf1571bccfa0.zip |
Fix examples smoke test fail (#8923)
Diffstat (limited to 'examples')
-rw-r--r-- | examples/ssr/src/pages/login.astro | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/examples/ssr/src/pages/login.astro b/examples/ssr/src/pages/login.astro index 51ad74008..030838a64 100644 --- a/examples/ssr/src/pages/login.astro +++ b/examples/ssr/src/pages/login.astro @@ -14,10 +14,10 @@ import Container from '../components/Container.astro'; <script type="module" is:inline> document.addEventListener('DOMContentLoaded', () => { - console.log('loaded'); - document.querySelector('form').addEventListener('submit', (e) => { + const form = document.querySelector('form'); + if (!form) throw new Error('Form not found'); + form.addEventListener('submit', (e) => { e.preventDefault(); - const form = e.target; const formData = new FormData(form); const data = Object.fromEntries(formData); @@ -26,10 +26,13 @@ import Container from '../components/Container.astro'; body: JSON.stringify(data), }) .then((res) => res.json()) - .then((data) => { - document.querySelector('#result').innerHTML = - 'Progressive login was successful! you will be redirected to the store in 3 seconds'; - setTimeout(() => (location.href = '/'), 3000); + .then(() => { + const result = document.querySelector('#result'); + if (result) { + result.innerHTML = + 'Progressive login was successful! you will be redirected to the store in 3 seconds'; + setTimeout(() => (location.href = '/'), 3000); + } }); }); }); |