#Delete cookies in Astro component

17 messages · Page 1 of 1 (latest)

umbral badge
#

If you Astro.cookies.delete('ps'); outside of the IF you cant delete it - but you can delete it inside ?

umbral badge
#

this is client side code, not in frontmatter ?

nocturne owl
#

No client side code

#

All are written in Astro code fence

#

So is an unexpected behavior when there are no error message from Astro

umbral badge
#

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

nocturne owl
umbral badge
#

Aye - i just added nodejs - its working fine.

umbral badge
#

each component frontmatter is executed on serverside, if thats done before the frontmatter of the index, that could be it

umbral badge
umbral badge
#

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

umbral badge
#

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.

nocturne owl
umbral badge
#

Hmm yes, but this would ony apply to the cookies set in SSR - not the client-side cookies.

#

What happends if you client:only your Alert ?