#Delete cookies in Astro component
17 messages · Page 1 of 1 (latest)
this is client side code, not in frontmatter ?
No client side code
All are written in Astro code fence
So is an unexpected behavior when there are no error message from Astro
This works for me
if (type === Astro.cookies.get('ps').value) {
console.log(type) // <- It show a message in terminal.
Astro.cookies.delete('ps');
}
else {
Astro.cookies.set('ps', type);
}```
as expected
its writing "test" every second reload, and cookie appears/disappears
You could try this code by uncomment the set cookies and comment cookies:
https://stackblitz.com/edit/github-nf1tnk-ca3kww?file=src%2Fpages%2Findex.astro
Aye - i just added nodejs - its working fine.
maybe this is a problem related to how Frontmatter is included / compiled / added after eachother
each component frontmatter is executed on serverside, if thats done before the frontmatter of the index, that could be it
also note, when you edit just "index.astro", then "alert.astro" isnt reloaded - the frontmatter isnt re-run, and thereby the cookie-set/get isnt run in Alert
The problem isnt as much with Astro as with how the hotloader works - if you were to rebuild all components everywhere when one component updates, you might as well just not use hotload.
Also note that the way youve built this code, it will only work SSR - not SSG
Can you point me to the description of the limitation ? I would like to know how this can be a limitation of Astro, except if its bc of SSG.
When i test the above stackblitz where index.astro sets the cookie and Alert.astro reads and deletes the cookie and its all SSG frontmatter, the alert.astro doesnt run when index.astro is changed in hot-reload.
If code isnt run - its not performing. My guess is that this could be a couple of problems; or just the stackblitz example that had an extra issue.