diff --git a/apps/website/e2e/workshop.spec.ts b/apps/website/e2e/workshop.spec.ts
index ca584ff63e5..6aa8e82eef8 100644
--- a/apps/website/e2e/workshop.spec.ts
+++ b/apps/website/e2e/workshop.spec.ts
@@ -85,6 +85,57 @@ test.describe('Models catalog', () => {
await expect(page.getByTestId('workshop-hero')).toBeVisible()
})
+ test('a model page returns to the shelf it was opened from', async ({
+ page
+ }) => {
+ await page.goto('/models/')
+ await page.getByTestId('section-generate-videos-open').click()
+ await expect(page.getByRole('heading', { level: 1 })).toContainText(
+ 'Generate videos'
+ )
+ await page
+ .getByTestId('workshop-models-grid')
+ .getByTestId('workshop-model-card')
+ .first()
+ .click()
+
+ const back = page.getByTestId('model-back')
+ await expect(back).toHaveText('Back to Generate videos')
+ await back.click()
+ await expect(page.getByRole('heading', { level: 1 })).toContainText(
+ 'Generate videos'
+ )
+ await expect(page.getByTestId('workshop-sections')).toHaveCount(0)
+ })
+
+ test('the search field stays put as the results swap under it', async ({
+ page
+ }) => {
+ await page.goto('/models/')
+ await expect(page.getByTestId('workshop-sections')).toBeVisible()
+ await page.evaluate(() => window.scrollTo(0, 700))
+ const search = page.getByTestId('workshop-search')
+
+ // Nothing else is clicked between the two measurements: a click scrolls its
+ // own target into view first, which would move the page under the field.
+ await search.fill('kling')
+ await expect(
+ page
+ .getByTestId('workshop-models-grid')
+ .getByTestId('workshop-model-card')
+ .first()
+ ).toContainText('Kling')
+ const searching = await search.boundingBox()
+
+ await search.fill('')
+ await expect(page.getByTestId('workshop-sections')).toBeVisible()
+ const cleared = await search.boundingBox()
+
+ if (!searching || !cleared)
+ throw new Error('the search field was never on screen to measure')
+ expect(cleared.y).toBeCloseTo(searching.y, 0)
+ })
+
test('cards open canonical model pages with related models', async ({
page
}) => {
diff --git a/apps/website/src/components/workshop/CatalogueBackLink.test.ts b/apps/website/src/components/workshop/CatalogueBackLink.test.ts
new file mode 100644
index 00000000000..d36d5f2be41
--- /dev/null
+++ b/apps/website/src/components/workshop/CatalogueBackLink.test.ts
@@ -0,0 +1,31 @@
+// @vitest-environment happy-dom
+import { render, screen, waitFor } from '@testing-library/vue'
+import { afterEach, describe, expect, it } from 'vitest'
+
+import { rememberShelf } from '../../lib/workshop/shelf-memory'
+import CatalogueBackLink from './CatalogueBackLink.vue'
+
+afterEach(() => {
+ sessionStorage.clear()
+})
+
+describe('CatalogueBackLink', () => {
+ it('offers the whole catalogue when no shelf was left behind', () => {
+ render(CatalogueBackLink)
+
+ const link = screen.getByTestId('model-back')
+ expect(link.textContent.trim()).toBe('Back to all models')
+ expect(link.getAttribute('href')).toBe('/models')
+ })
+
+ it('offers the shelf the visitor came from', async () => {
+ rememberShelf('generate-videos')
+ render(CatalogueBackLink)
+
+ await waitFor(() => {
+ const link = screen.getByTestId('model-back')
+ expect(link.textContent.trim()).toBe('Back to Generate videos')
+ expect(link.getAttribute('href')).toBe('/models?useCase=generate-videos')
+ })
+ })
+})
diff --git a/apps/website/src/components/workshop/CatalogueBackLink.vue b/apps/website/src/components/workshop/CatalogueBackLink.vue
new file mode 100644
index 00000000000..b33892ae832
--- /dev/null
+++ b/apps/website/src/components/workshop/CatalogueBackLink.vue
@@ -0,0 +1,42 @@
+
+
+
+
+
+ {{
+ category
+ ? t('workshop.model.backTo', locale).replace('{category}', category)
+ : t('workshop.model.back', locale)
+ }}
+
+
diff --git a/apps/website/src/components/workshop/ExamplesTab.vue b/apps/website/src/components/workshop/ExamplesTab.vue
index 8e6162a5921..50dfcd18156 100644
--- a/apps/website/src/components/workshop/ExamplesTab.vue
+++ b/apps/website/src/components/workshop/ExamplesTab.vue
@@ -73,7 +73,7 @@ function actionFor(example: PlaygroundExample, active = false) {
they fit in a row of their own. -->
@@ -265,15 +202,7 @@ function fileType(file: FileValue): string {
role="alert"
class="text-primary-comfy-red text-xs"
>
- {{ t(rejection, locale).replace('{count}', String(limit)) }}
- {{
- t(
- imageOnly
- ? 'workshop.field.imagesUnchanged'
- : 'workshop.field.filesUnchanged',
- locale
- )
- }}
+ {{ rejectionMessage }}
diff --git a/apps/website/src/components/workshop/HeaderAccount.test.ts b/apps/website/src/components/workshop/HeaderAccount.test.ts
index 9da5eea9653..432ba427f1b 100644
--- a/apps/website/src/components/workshop/HeaderAccount.test.ts
+++ b/apps/website/src/components/workshop/HeaderAccount.test.ts
@@ -137,7 +137,7 @@ describe('HeaderAccount', () => {
await userEvent
.setup()
.click(screen.getByRole('button', { name: /account/i }))
- const buy = screen.getByRole('menuitem', { name: 'Buy credits' })
+ const buy = screen.getByRole('menuitem', { name: 'Add credits' })
expect(buy.getAttribute('href')).toBe(
`${WORKSHOP_CLOUD_BASE_URL}/?settings=plan-credits`
)
diff --git a/apps/website/src/components/workshop/ImageSourcePreview.vue b/apps/website/src/components/workshop/ImageSourcePreview.vue
index 884680bd175..4e818d339da 100644
--- a/apps/website/src/components/workshop/ImageSourcePreview.vue
+++ b/apps/website/src/components/workshop/ImageSourcePreview.vue
@@ -1,4 +1,5 @@
+
+
+
+
+
+
+ {{ fileType }}
+
+
+ {{
+ formatSize(file.size)
+ }}
+
+
+
diff --git a/apps/website/src/components/workshop/MediaSourcePreview.test.ts b/apps/website/src/components/workshop/VideoSourcePreview.test.ts
similarity index 74%
rename from apps/website/src/components/workshop/MediaSourcePreview.test.ts
rename to apps/website/src/components/workshop/VideoSourcePreview.test.ts
index 3ae8db904ea..77847b0b685 100644
--- a/apps/website/src/components/workshop/MediaSourcePreview.test.ts
+++ b/apps/website/src/components/workshop/VideoSourcePreview.test.ts
@@ -4,20 +4,20 @@ import { expect, it, vi } from 'vitest'
import { createSSRApp, h } from 'vue'
import { renderToString } from 'vue/server-renderer'
-import MediaSourcePreview from './MediaSourcePreview.vue'
+import VideoSourcePreview from './VideoSourcePreview.vue'
it('waits until mounting before creating a local media URL', async () => {
const create = vi.spyOn(URL, 'createObjectURL')
const file = new File(['video'], 'source.mp4', { type: 'video/mp4' })
- const props = { file, name: 'Source video', kind: 'video' as const }
+ const props = { file, name: 'Source video' }
const html = await renderToString(
createSSRApp({
- render: () => h(MediaSourcePreview, props)
+ render: () => h(VideoSourcePreview, props)
})
)
expect(create).not.toHaveBeenCalled()
expect(html).not.toContain('blob:')
- render(MediaSourcePreview, { props })
+ render(VideoSourcePreview, { props })
const video = await screen.findByLabelText('Source video')
expect(video.getAttribute('src')).toMatch(/^blob:/)
expect(create).toHaveBeenCalledWith(file)
@@ -30,11 +30,10 @@ it('switches between remote examples and local uploads, revoking only its owned
.mockReturnValueOnce('blob:second')
const revoke = vi.spyOn(URL, 'revokeObjectURL').mockImplementation(() => {})
const props = {
- kind: 'video' as const,
name: 'Input video',
src: 'https://assets.example/source.mp4'
}
- const { rerender, unmount } = render(MediaSourcePreview, { props })
+ const { rerender, unmount } = render(VideoSourcePreview, { props })
function video() {
const element = screen.getByLabelText('Input video')
if (!(element instanceof HTMLVideoElement))
@@ -59,16 +58,3 @@ it('switches between remote examples and local uploads, revoking only its owned
unmount()
expect(revoke).not.toHaveBeenCalledWith(props.src)
})
-
-it('renders an audio source as an accessible audio element', () => {
- render(MediaSourcePreview, {
- props: {
- kind: 'audio',
- name: 'Input audio',
- src: 'https://assets.example/source.mp3'
- }
- })
- const element = screen.getByLabelText('Input audio')
- expect(element).toBeInstanceOf(HTMLAudioElement)
- expect(element.getAttribute('src')).toBe('https://assets.example/source.mp3')
-})
diff --git a/apps/website/src/components/workshop/MediaSourcePreview.vue b/apps/website/src/components/workshop/VideoSourcePreview.vue
similarity index 56%
rename from apps/website/src/components/workshop/MediaSourcePreview.vue
rename to apps/website/src/components/workshop/VideoSourcePreview.vue
index c313332185d..85addd286de 100644
--- a/apps/website/src/components/workshop/MediaSourcePreview.vue
+++ b/apps/website/src/components/workshop/VideoSourcePreview.vue
@@ -2,10 +2,9 @@
import { useMounted, useObjectUrl } from '@vueuse/core'
import { computed } from 'vue'
-const { file, src, kind, name } = defineProps<{
+const { file, src, name } = defineProps<{
file?: File
src?: string
- kind: 'video' | 'audio'
name: string
}>()
const mounted = useMounted()
@@ -15,22 +14,13 @@ const source = computed(() => objectUrl.value ?? src)
-
diff --git a/apps/website/src/components/workshop/WorkshopModelsGrid.test.ts b/apps/website/src/components/workshop/WorkshopModelsGrid.test.ts
index c2c8309417a..be65dd7f9c0 100644
--- a/apps/website/src/components/workshop/WorkshopModelsGrid.test.ts
+++ b/apps/website/src/components/workshop/WorkshopModelsGrid.test.ts
@@ -4,6 +4,7 @@ import { render, screen } from '@testing-library/vue'
import { afterEach, describe, expect, it } from 'vitest'
import type { WorkshopModel } from '../../config/models-catalogue'
+import { lastShelf } from '../../lib/workshop/shelf-memory'
import WorkshopModelsGrid from './WorkshopModelsGrid.vue'
const models: WorkshopModel[] = [
@@ -54,6 +55,7 @@ function search() {
describe('WorkshopModelsGrid', () => {
afterEach(() => {
history.replaceState(null, '', '/')
+ sessionStorage.clear()
})
it('searches by name and provider', async () => {
@@ -154,6 +156,13 @@ describe('WorkshopModelsGrid', () => {
expect(cardNames()[0]).toContain('Flux')
})
+ it('forgets the shelf a previous visit was left on', () => {
+ sessionStorage.setItem('comfy-models-shelf', 'generate-videos')
+ render(WorkshopModelsGrid, { props: { models } })
+
+ expect(lastShelf()).toBe('all')
+ })
+
it('clears search and filters together from the empty state', async () => {
const user = userEvent.setup()
render(WorkshopModelsGrid, { props: { models } })
diff --git a/apps/website/src/components/workshop/WorkshopModelsGrid.vue b/apps/website/src/components/workshop/WorkshopModelsGrid.vue
index dd6b34aaf6b..b0c88e8c9b9 100644
--- a/apps/website/src/components/workshop/WorkshopModelsGrid.vue
+++ b/apps/website/src/components/workshop/WorkshopModelsGrid.vue
@@ -8,7 +8,7 @@ import {
DropdownMenuRoot,
DropdownMenuTrigger
} from 'reka-ui'
-import { computed, nextTick, onMounted, ref, watch } from 'vue'
+import { computed, nextTick, onMounted, ref, useTemplateRef, watch } from 'vue'
import Button from '@/components/ui/button/Button.vue'
import { groupModels } from '../../config/model-family'
@@ -31,6 +31,8 @@ import {
} from '../../config/models-catalogue'
import type { Locale, TranslationKey } from '../../i18n/translations'
import { t } from '../../i18n/translations'
+import { rememberShelf } from '../../lib/workshop/shelf-memory'
+import { useCaseLabelKey } from '../../lib/workshop/use-case-label'
import type { FacetMenuOption } from './WorkshopFilterMenu.vue'
import WorkshopFilterMenu from './WorkshopFilterMenu.vue'
import WorkshopModelCard from './WorkshopModelCard.vue'
@@ -58,24 +60,27 @@ onMounted(() => {
capabilities.value = [...(initial.capabilities ?? [])]
providers.value = [...(initial.providers ?? [])]
modalities.value = [...(initial.modalities ?? [])]
+ // The whole catalogue is a shelf too, and it has to replace the one the tab
+ // was left on, or the way back leads to a category never visited.
+ rememberShelf(useCase.value)
})
// A row title clicked far down the page opens a much shorter screen, which
// would otherwise leave the viewport parked on the footer.
-watch(useCase, () => void nextTick(() => window.scrollTo({ top: 0 })))
+watch(useCase, (shelf) => {
+ rememberShelf(shelf)
+ void nextTick(() => window.scrollTo({ top: 0 }))
+})
+
+// Typing swaps the rows for a grid and clearing swaps them back, which moves
+// everything under the search field. Following the field keeps it in the same
+// place both ways, instead of the page landing wherever the new height falls.
+const toolbar = useTemplateRef('toolbar')
+watch(
+ () => query.value.trim() !== '',
+ () => void nextTick(() => toolbar.value?.scrollIntoView({ block: 'start' }))
+)
-const useCaseLabelKey: Record = {
- all: 'workshop.useCase.all',
- other: 'workshop.sections.otherFormats',
- 'generate-images': 'workshop.useCase.generateImages',
- 'edit-images': 'workshop.useCase.editImages',
- 'generate-videos': 'workshop.useCase.generateVideos',
- 'animate-images': 'workshop.useCase.animateImages',
- 'edit-videos': 'workshop.useCase.editVideos',
- '3d': 'workshop.useCase.3d',
- audio: 'workshop.useCase.audio',
- text: 'workshop.useCase.text'
-}
const sortLabelKey: Record = {
popular: 'workshop.sort.popular',
name: 'workshop.sort.name',
@@ -227,7 +232,8 @@ const menuItemClass =
{
+ sessionStorage.clear()
+})
+
+describe('shelf memory', () => {
+ it('reads back the shelf the visitor was standing on', () => {
+ rememberShelf('generate-videos')
+ expect(lastShelf()).toBe('generate-videos')
+ })
+
+ it('remembers nothing before the catalogue has been browsed', () => {
+ expect(lastShelf()).toBeUndefined()
+ })
+
+ it('ignores a value that is no longer a shelf', () => {
+ sessionStorage.setItem('comfy-models-shelf', 'retired-category')
+ expect(lastShelf()).toBeUndefined()
+ })
+
+ it('says nothing when the stored value is empty', () => {
+ sessionStorage.setItem('comfy-models-shelf', '')
+ expect(lastShelf()).toBeUndefined()
+ })
+
+ it('browses on when the browser refuses its own storage', () => {
+ const denied = vi
+ .spyOn(window, 'sessionStorage', 'get')
+ .mockImplementation(() => {
+ throw new Error('access to storage is denied')
+ })
+
+ try {
+ expect(() => rememberShelf('generate-videos')).not.toThrow()
+ expect(lastShelf()).toBeUndefined()
+ } finally {
+ denied.mockRestore()
+ }
+ })
+})
diff --git a/apps/website/src/lib/workshop/shelf-memory.ts b/apps/website/src/lib/workshop/shelf-memory.ts
new file mode 100644
index 00000000000..7911a743b64
--- /dev/null
+++ b/apps/website/src/lib/workshop/shelf-memory.ts
@@ -0,0 +1,31 @@
+import type { UseCase } from '../../config/models-catalogue'
+import { USE_CASES } from '../../config/models-catalogue'
+
+export type Shelf = UseCase | 'all' | 'other'
+
+const KEY = 'comfy-models-shelf'
+
+// The catalogue navigates with the client router, which leaves no referrer, so
+// the shelf a visitor is standing on is remembered for the page they open from
+// it. It lives in session storage: their tab, their journey, gone when it ends.
+export function rememberShelf(shelf: Shelf): void {
+ try {
+ sessionStorage.setItem(KEY, shelf)
+ } catch {
+ // A browser that refuses storage still browses; it just starts each page
+ // from the whole catalogue.
+ }
+}
+
+export function lastShelf(): Shelf | undefined {
+ try {
+ return asShelf(sessionStorage.getItem(KEY))
+ } catch {
+ return undefined
+ }
+}
+
+function asShelf(value: string | null): Shelf | undefined {
+ if (value === 'all' || value === 'other') return value
+ return USE_CASES.find((useCase) => useCase === value)
+}
diff --git a/apps/website/src/lib/workshop/use-case-label.ts b/apps/website/src/lib/workshop/use-case-label.ts
new file mode 100644
index 00000000000..771835bb1ca
--- /dev/null
+++ b/apps/website/src/lib/workshop/use-case-label.ts
@@ -0,0 +1,18 @@
+import type { UseCase } from '../../config/models-catalogue'
+import type { TranslationKey } from '../../i18n/translations'
+
+export const useCaseLabelKey: Record<
+ UseCase | 'all' | 'other',
+ TranslationKey
+> = {
+ all: 'workshop.useCase.all',
+ other: 'workshop.sections.otherFormats',
+ 'generate-images': 'workshop.useCase.generateImages',
+ 'edit-images': 'workshop.useCase.editImages',
+ 'generate-videos': 'workshop.useCase.generateVideos',
+ 'animate-images': 'workshop.useCase.animateImages',
+ 'edit-videos': 'workshop.useCase.editVideos',
+ '3d': 'workshop.useCase.3d',
+ audio: 'workshop.useCase.audio',
+ text: 'workshop.useCase.text'
+}
diff --git a/apps/website/src/routes/models/[slug].astro b/apps/website/src/routes/models/[slug].astro
index 1a98486b2b2..c701e6b3710 100644
--- a/apps/website/src/routes/models/[slug].astro
+++ b/apps/website/src/routes/models/[slug].astro
@@ -2,6 +2,7 @@
import { ArrowRight } from '@lucide/vue'
import type { GetStaticPaths } from 'astro'
import BaseLayout from '../../layouts/BaseLayout.astro'
+import CatalogueBackLink from '../../components/workshop/CatalogueBackLink.vue'
import ModelDetail from '../../components/workshop/ModelDetail.vue'
import ModelStatus from '../../components/workshop/ModelStatus.vue'
import ModelSupport from '../../components/workshop/ModelSupport.vue'
@@ -34,23 +35,7 @@ const pillClass =
noindex
>