[GH-ISSUE #4757] [Issue]: Re-imported background with the same filename displays the deleted image #2618

Closed
opened 2026-10-21 05:51:29 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @SpicyMarinara on GitHub (Aug 8, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4757

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Deleting a background and importing a new image with the same filename causes Marinara to display the old, deleted image from the browser cache.

Expected behavior

The newly imported background should be displayed after replacing a deleted background with an image using the same filename.

Actual behavior

Marinara displays the previously deleted image instead of the newly imported image. Hard refresh did not resolve the issue.

Steps to reproduce

  1. Delete an existing background image.
  2. Import a different background image.
  3. Rename the new image to the deleted image's filename.
  4. Use the renamed image as the background.
  5. Observe that the old, deleted image is displayed.

Environment

  • Marinara Engine version: v2.4.1
  • Install type: source
  • OS + version: Windows 11
  • Browser or app shell: Not provided

Logs, screenshots, or video

No logs, screenshots, or video provided.

Additional context

The reported root cause is the background file-serving route setting Cache-Control: public, max-age=31536000, immutable in packages/server/src/routes/backgrounds.routes.ts (line 715). Re-importing with the same filename reuses the same URL, such as /api/backgrounds/file/forest_camping, so the browser serves its stale cached copy. Backgrounds are rendered through CSS background-image, and Ctrl+Shift+R did not resolve the issue. The server-side thumbnail cache reportedly keys on modification time and is not affected. Possible fixes include adding a cache-busting query parameter based on modification time or a content hash, or replacing immutable long-term caching with shorter caching plus ETag/Last-Modified validation. Chatting mode was RP.

Discord thread: Importing a deleted background with the same filename serves a stale browser-cached copy
Discord thread link: https://discord.com/channels/1417099416812392641/1535653751900344340
Requested by: Marinara (marinara_spaghetti, Discord ID 169561011928432653)

Discord thread transcript (1 message)
[2026-08-08T14:19:45.520Z] Neppy ♡: OS: Windows 11
Installation: Git
ME: v2.4.1
Chatting Mode: RP

When I delete a background image, import a new one, and rename it to the deleted image, it displays the old (deleted) image instead of the new one.

This is what Mari in ME responded:
Root cause: Cache-Control: public, max-age=31536000, immutable

Line 715 of packages/server/src/routes/backgrounds.routes.ts — the file-serving route sets this header on every background image:
.header("Cache-Control", "public, max-age=31536000, immutable")

That's 1 year of caching with the immutable flag. immutable explicitly tells the browser: "this resource will never, ever change at this URL — don't even bother revalidating." When you re-import with the same filename, the URL is identical (/api/backgrounds/file/forest_camping), so the browser just serves the stale copy from disk cache.

A hard refresh should bypass this, but immutable is aggressive enough that some browsers won't fully invalidate it for resources loaded via CSS background-image (which is how Marinara renders chat backgrounds) rather than direct navigations. That's why Ctrl+Shift+R didn't fix it.

The server-side thumbnail cache is actually fine — it keys on mtime (modification time), so a re-uploaded file with a new mtime generates a fresh thumbnail. The problem is purely the browser HTTP cache.

The underlying bug:

Marinara treats background files as permanently immutable (max-age=31536000, immutable), but they're mutable — users can delete and re-upload with the same name. The fix would be to either append a cache-busting token (like ?v=<mtime> or ?v=<hash>) to the URL, or drop immutable and use a shorter max-age with ETag/Last-Modified validation. This is worth reporting to the Pasta Devs.

This answer used implementation-level source from packages/server/src/routes/backgrounds.routes.ts (lines 683-717) and packages/server/src/services/image/image-thumbnail.ts (lines 46-70).
[Discord message: https://discord.com/channels/1417099416812392641/1535653751900344340/1535653751900344340]

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @SpicyMarinara on GitHub (Aug 8, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4757 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Deleting a background and importing a new image with the same filename causes Marinara to display the old, deleted image from the browser cache. ## Expected behavior The newly imported background should be displayed after replacing a deleted background with an image using the same filename. ## Actual behavior Marinara displays the previously deleted image instead of the newly imported image. Hard refresh did not resolve the issue. ## Steps to reproduce 1. Delete an existing background image. 2. Import a different background image. 3. Rename the new image to the deleted image's filename. 4. Use the renamed image as the background. 5. Observe that the old, deleted image is displayed. ## Environment - Marinara Engine version: v2.4.1 - Install type: source - OS + version: Windows 11 - Browser or app shell: Not provided ## Logs, screenshots, or video No logs, screenshots, or video provided. ## Additional context The reported root cause is the background file-serving route setting Cache-Control: public, max-age=31536000, immutable in packages/server/src/routes/backgrounds.routes.ts (line 715). Re-importing with the same filename reuses the same URL, such as /api/backgrounds/file/forest_camping, so the browser serves its stale cached copy. Backgrounds are rendered through CSS background-image, and Ctrl+Shift+R did not resolve the issue. The server-side thumbnail cache reportedly keys on modification time and is not affected. Possible fixes include adding a cache-busting query parameter based on modification time or a content hash, or replacing immutable long-term caching with shorter caching plus ETag/Last-Modified validation. Chatting mode was RP. Discord thread: Importing a deleted background with the same filename serves a stale browser-cached copy Discord thread link: https://discord.com/channels/1417099416812392641/1535653751900344340 Requested by: Marinara (marinara_spaghetti, Discord ID 169561011928432653) <details> <summary>Discord thread transcript (1 message)</summary> ```text [2026-08-08T14:19:45.520Z] Neppy ♡: OS: Windows 11 Installation: Git ME: v2.4.1 Chatting Mode: RP When I delete a background image, import a new one, and rename it to the deleted image, it displays the old (deleted) image instead of the new one. This is what Mari in ME responded: Root cause: Cache-Control: public, max-age=31536000, immutable Line 715 of packages/server/src/routes/backgrounds.routes.ts — the file-serving route sets this header on every background image: .header("Cache-Control", "public, max-age=31536000, immutable") That's 1 year of caching with the immutable flag. immutable explicitly tells the browser: "this resource will never, ever change at this URL — don't even bother revalidating." When you re-import with the same filename, the URL is identical (/api/backgrounds/file/forest_camping), so the browser just serves the stale copy from disk cache. A hard refresh should bypass this, but immutable is aggressive enough that some browsers won't fully invalidate it for resources loaded via CSS background-image (which is how Marinara renders chat backgrounds) rather than direct navigations. That's why Ctrl+Shift+R didn't fix it. The server-side thumbnail cache is actually fine — it keys on mtime (modification time), so a re-uploaded file with a new mtime generates a fresh thumbnail. The problem is purely the browser HTTP cache. The underlying bug: Marinara treats background files as permanently immutable (max-age=31536000, immutable), but they're mutable — users can delete and re-upload with the same name. The fix would be to either append a cache-busting token (like ?v=<mtime> or ?v=<hash>) to the URL, or drop immutable and use a shorter max-age with ETag/Last-Modified validation. This is worth reporting to the Pasta Devs. This answer used implementation-level source from packages/server/src/routes/backgrounds.routes.ts (lines 683-717) and packages/server/src/services/image/image-thumbnail.ts (lines 46-70). [Discord message: https://discord.com/channels/1417099416812392641/1535653751900344340/1535653751900344340] ``` </details> ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:51:29 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Aug 8, 2026):

SpicyMarinara is taking this in the current assigned-issue sweep. I am preparing a focused draft PR against staging and will link it here shortly.

<!-- gh-comment-id:5226820152 --> @SpicyMarinara commented on GitHub (Aug 8, 2026): SpicyMarinara is taking this in the current assigned-issue sweep. I am preparing a focused draft PR against `staging` and will link it here shortly.
Author
Owner

@SpicyMarinara commented on GitHub (Aug 8, 2026):

Implementation is now tracked in draft PR #4761: https://github.com/Pasta-Devs/Marinara-Engine/pull/4761

<!-- gh-comment-id:5226823841 --> @SpicyMarinara commented on GitHub (Aug 8, 2026): Implementation is now tracked in draft PR #4761: https://github.com/Pasta-Devs/Marinara-Engine/pull/4761
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#2618
No description provided.