diff --git a/packages/astro/src/core/session.ts b/packages/astro/src/core/session.ts index eb2415b5c739..8401e8a84aa1 100644 --- a/packages/astro/src/core/session.ts +++ b/packages/astro/src/core/session.ts @@ -23,7 +23,7 @@ const VALID_COOKIE_REGEX = /^[\w-]+$/; interface SessionEntry { data: any; - expires?: number | 'flash'; + expires?: number; } export class AstroSession { @@ -122,7 +122,7 @@ export class AstroSession { * Sets a session value. The session is created if it does not exist. */ - set(key: string, value: T, { ttl }: { ttl?: number | 'flash' } = {}) { + set(key: string, value: T, { ttl }: { ttl?: number } = {}) { if (!key) { throw new AstroError({ ...SessionStorageSaveError, @@ -157,10 +157,6 @@ export class AstroSession { this.#dirty = true; } - flash(key: string, value: T) { - this.set(key, value, { ttl: 'flash' }); - } - /** * Destroys the session, clearing the cookie and storage if it exists. */ @@ -320,10 +316,6 @@ export class AstroSession { const expired = typeof value.expires === 'number' && value.expires < now; if (!this.#data.has(key) && !this.#toDelete.has(key) && !expired) { this.#data.set(key, value); - if (value?.expires === 'flash') { - this.#toDelete.add(key); - this.#dirty = true; - } } } diff --git a/packages/astro/test/fixtures/sessions/src/middleware.ts b/packages/astro/test/fixtures/sessions/src/middleware.ts index cf53e9cfd2df..7f56f11f364f 100644 --- a/packages/astro/test/fixtures/sessions/src/middleware.ts +++ b/packages/astro/test/fixtures/sessions/src/middleware.ts @@ -7,20 +7,6 @@ export const onRequest = defineMiddleware(async (context, next) => { // Skip requests for prerendered pages if (context.isPrerendered) return next(); - if(context.url.searchParams.has('setFlash') && context.url.pathname === '/') { - context.session.flash('middleware-flash', `Flashed message at ${new Date().toISOString()}`); - } - - if(context.url.pathname === '/next-rewrite-middleware') { - context.session.flash('middleware-flash', `Flashed rewrite message at ${new Date().toISOString()}`); - return next('/'); - } - - if(context.url.pathname === '/ctx-rewrite-middleware') { - context.session.flash('middleware-flash', `Flashed rewrite message at ${new Date().toISOString()}`); - return context.rewrite(new Request(new URL('/', context.url))); - } - const { action, setActionResult, serializeActionResult } = getActionContext(context); diff --git a/packages/astro/test/fixtures/sessions/src/pages/flash-rewrite.astro b/packages/astro/test/fixtures/sessions/src/pages/flash-rewrite.astro deleted file mode 100644 index 9d7654746a97..000000000000 --- a/packages/astro/test/fixtures/sessions/src/pages/flash-rewrite.astro +++ /dev/null @@ -1,4 +0,0 @@ ---- -Astro.session.flash('flash-value', `Flashed value at ${new Date().toISOString()}`); -return Astro.rewrite('/'); ---- diff --git a/packages/astro/test/fixtures/sessions/src/pages/flash.astro b/packages/astro/test/fixtures/sessions/src/pages/flash.astro deleted file mode 100644 index a00a66506582..000000000000 --- a/packages/astro/test/fixtures/sessions/src/pages/flash.astro +++ /dev/null @@ -1,4 +0,0 @@ ---- -Astro.session.flash('flash-value', `Flashed value at ${new Date().toISOString()}`); -return Astro.redirect('/'); ---- diff --git a/packages/astro/test/fixtures/sessions/src/pages/index.astro b/packages/astro/test/fixtures/sessions/src/pages/index.astro index 584f30fb1cc0..30d6a1618796 100644 --- a/packages/astro/test/fixtures/sessions/src/pages/index.astro +++ b/packages/astro/test/fixtures/sessions/src/pages/index.astro @@ -1,7 +1,5 @@ --- const value = await Astro.session.get('value'); -const flash = await Astro.session.get('flash-value'); -const middlewareFlash = await Astro.session.get('middleware-flash'); --- @@ -11,8 +9,5 @@ const middlewareFlash = await Astro.session.get('middleware-flash');

Hi

{value}

-

Flash: {flash}

-

middlewareFlash: {middlewareFlash}

-

Set flash

🛒 diff --git a/packages/astro/test/units/sessions/astro-session.test.js b/packages/astro/test/units/sessions/astro-session.test.js index f76cd7d7936f..0bbefee7355f 100644 --- a/packages/astro/test/units/sessions/astro-session.test.js +++ b/packages/astro/test/units/sessions/astro-session.test.js @@ -167,26 +167,6 @@ test('AstroSession - Data Persistence', async (t) => { }); - await t.test('should not write flash session data to storage a second time', async () => { - let storedData; - const mockStorage = { - get: async () => stringify(new Map([['key', { data: 'value', expires: "flash" }]])), - setItem: async (_key, value) => { - storedData = value; - }, - }; - const session = createSession(defaultConfig, defaultMockCookies, mockStorage); - - const value = await session.get('key'); - - assert.equal(value, 'value'); - - await session[PERSIST_SYMBOL](); - - const emptyMap = devalueStringify(new Map()); - assert.equal(storedData, emptyMap); - }) - });