fix search modal race condition and add 304 support for images

Route all search modal open/close through the JS hook via custom DOM
events so the _closing flag is always correctly managed. Prevents the
modal flashing back after Escape when a search response is in flight.

Add If-None-Match / 304 Not Modified handling to the image controller
so browsers don't re-download images on revalidation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-02-13 16:21:51 +00:00
parent 994f6fe0d6
commit 44933acebb
3 changed files with 98 additions and 74 deletions

View File

@@ -383,10 +383,7 @@ defmodule SimpleshopThemeWeb.ShopComponents.Layout do
class="search-modal"
style={"position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1001; display: #{if @search_open, do: "flex", else: "none"}; align-items: flex-start; justify-content: center; padding-top: 10vh;"}
phx-hook="SearchModal"
phx-click={
Phoenix.LiveView.JS.hide(to: "#search-modal")
|> Phoenix.LiveView.JS.push("clear_search")
}
phx-click={Phoenix.LiveView.JS.dispatch("close-search", to: "#search-modal")}
>
<div
class="search-modal-content w-full max-w-xl mx-4"
@@ -437,10 +434,7 @@ defmodule SimpleshopThemeWeb.ShopComponents.Layout do
type="button"
class="w-8 h-8 flex items-center justify-center transition-all"
style="color: var(--t-text-tertiary); background: none; border: none; cursor: pointer; border-radius: var(--t-radius-button);"
phx-click={
Phoenix.LiveView.JS.hide(to: "#search-modal")
|> Phoenix.LiveView.JS.push("clear_search")
}
phx-click={Phoenix.LiveView.JS.dispatch("close-search", to: "#search-modal")}
aria-label="Close search"
>
<svg
@@ -474,7 +468,7 @@ defmodule SimpleshopThemeWeb.ShopComponents.Layout do
style="text-decoration: none; color: inherit;"
onmouseenter="this.style.background='var(--t-surface-sunken)'"
onmouseleave="this.style.background='transparent'"
phx-click={Phoenix.LiveView.JS.hide(to: "#search-modal")}
phx-click={Phoenix.LiveView.JS.dispatch("close-search", to: "#search-modal")}
>
<div
:if={item.image_url}
@@ -821,11 +815,7 @@ defmodule SimpleshopThemeWeb.ShopComponents.Layout do
type="button"
class="header-icon-btn w-9 h-9 flex items-center justify-center transition-all"
style="color: var(--t-text-secondary); background: none; border: none; cursor: pointer; border-radius: var(--t-radius-button);"
phx-click={
Phoenix.LiveView.JS.push("open_search")
|> Phoenix.LiveView.JS.show(to: "#search-modal", display: "flex")
|> Phoenix.LiveView.JS.focus(to: "#search-input")
}
phx-click={Phoenix.LiveView.JS.dispatch("open-search", to: "#search-modal")}
aria-label="Search"
>
<svg