Repository navigation
fix(website): improve Models performance, input recovery and SDK examples #17604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4f1b8d9
test(website): reproduce catalogue download and offscreen video overhead
benjcooley 0d3dc5d
fix(website): bound model preview work and keep catalogue joins out o…
benjcooley 061352a
fix(website): release swapped previews and keep zod out of the catalo…
benjcooley 96d1f5d
test(website): keep the whole-route script ceiling beside the catalog…
benjcooley af6c212
fix(website): execute model examples through the published SDKs
benjcooley 1162e24
fix(website): retain model inputs through sign-in and copied examples
benjcooley 2e8582e
fix(website): enable catalogue search after hydration
benjcooley 9b53ea3
fix(website): preserve sign-in drafts on HTTP previews
benjcooley 94063c3
fix(website): retain recoverable drafts and address review feedback
benjcooley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { expect } from '@playwright/test' | ||
|
|
||
| import { test } from './fixtures/modelsAccount' | ||
|
|
||
| test('GPT Image generation pages are discoverable as text-to-image while published URLs remain valid', async ({ | ||
| page | ||
| }) => { | ||
| const hydrated = Promise.withResolvers<void>() | ||
| const moduleRequested = page.waitForRequest( | ||
| '**/_website/ModelsCatalogue.*.js' | ||
| ) | ||
| await page.route('**/_website/ModelsCatalogue.*.js', async (route) => { | ||
| await hydrated.promise | ||
| await route.continue() | ||
| }) | ||
| try { | ||
| await page.goto('/models/?useCase=generate-images', { waitUntil: 'commit' }) | ||
| await moduleRequested | ||
| await expect(page.getByTestId('workshop-search')).toBeDisabled() | ||
| } finally { | ||
| hydrated.resolve() | ||
| } | ||
| await page.getByTestId('workshop-search').fill('gpt image') | ||
| const cards = page | ||
| .getByTestId('workshop-models-grid') | ||
| .getByTestId('workshop-model-card') | ||
| await expect(cards).toHaveCount(3) | ||
| await page.getByRole('link', { name: /GPT Image 1\.5/ }).click() | ||
| await expect(page).toHaveURL( | ||
| /\/models\/openai--gpt-image-1\.5--edit-images\/$/ | ||
| ) | ||
| await expect( | ||
| page.getByRole('textbox', { name: 'Prompt', exact: true }) | ||
| ).toBeVisible() | ||
| await page.goto('/models/?useCase=edit-images') | ||
| await page.getByTestId('workshop-search').fill('gpt image') | ||
| await expect(cards).toHaveCount(0) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| import type { Page } from '@playwright/test' | ||
| import { expect } from '@playwright/test' | ||
|
|
||
| import { test } from './fixtures/modelsAccount' | ||
|
|
||
| /** Same-origin script resources the page has requested so far, by URL. */ | ||
| function requestedScripts(page: Page) { | ||
| return page.evaluate(() => | ||
| performance | ||
| .getEntriesByType('resource') | ||
| .filter( | ||
| (entry): entry is PerformanceResourceTiming => | ||
| entry instanceof PerformanceResourceTiming | ||
| ) | ||
| .flatMap((entry) => { | ||
| const url = new URL(entry.name) | ||
| return url.origin === location.origin && url.pathname.endsWith('.js') | ||
| ? [[entry.name, entry.decodedBodySize] as const] | ||
| : [] | ||
| }) | ||
| ) | ||
| } | ||
|
|
||
| test('catalogue browsing stays within its JavaScript budget', async ({ | ||
| page | ||
| }) => { | ||
| // Every page pays for the layout islands (header, footer, translations, | ||
| // analytics). Charge the catalogue only for what it adds on top of those, | ||
| // so a header change cannot fail this test and a catalogue regression | ||
| // cannot hide behind a shrink elsewhere. | ||
| // The default resource-timing buffer holds 250 entries and drops the rest | ||
| // silently; a late catalogue chunk must not fall off the end. | ||
| await page.addInitScript(() => performance.setResourceTimingBufferSize(2000)) | ||
| await page.goto('/') | ||
| const shared = new Set((await requestedScripts(page)).map(([name]) => name)) | ||
|
|
||
| await page.goto('/models/') | ||
| await page.getByTestId('workshop-search').fill('kling') | ||
| await page.getByRole('heading', { level: 1 }).click() | ||
| await expect( | ||
| page | ||
| .getByTestId('workshop-models-grid') | ||
| .getByTestId('workshop-model-card') | ||
| .first() | ||
| ).toContainText('Kling') | ||
| const scripts = await requestedScripts(page) | ||
| const catalogueBytes = scripts | ||
| .filter(([name]) => !shared.has(name)) | ||
| .reduce((total, [, bytes]) => total + bytes, 0) | ||
| expect(catalogueBytes).toBeGreaterThan(0) | ||
| expect(catalogueBytes).toBeLessThan(900_000) | ||
| // The whole-route ceiling stays as well: catalogue code that migrated into | ||
| // a chunk the homepage also loads would pass the delta and still be paid | ||
| // for by every visitor to /models/. | ||
| const totalBytes = scripts.reduce((total, [, bytes]) => total + bytes, 0) | ||
| expect(totalBytes).toBeLessThan(1_800_000) | ||
| }) | ||
|
|
||
| test('video cards load on screen and stop playing when scrolled away', async ({ | ||
| page | ||
| }) => { | ||
| await page.goto('/models/') | ||
| await page.getByTestId('workshop-filter').click() | ||
| const videos = page.getByTestId('section-generate-videos').locator('video') | ||
| await expect.poll(() => videos.count()).toBeGreaterThan(0) | ||
| await expect | ||
| .poll(() => | ||
| videos.evaluateAll((elements: HTMLVideoElement[]) => | ||
| elements.every((video) => video.currentSrc === '' && video.paused) | ||
| ) | ||
| ) | ||
| .toBe(true) | ||
|
|
||
| const first = videos.first() | ||
| await first.scrollIntoViewIfNeeded() | ||
| await expect | ||
| .poll(() => | ||
| first.evaluate( | ||
| (video: HTMLVideoElement) => video.readyState >= 2 && !video.paused | ||
| ) | ||
| ) | ||
| .toBe(true) | ||
| await page.getByRole('heading', { level: 1 }).scrollIntoViewIfNeeded() | ||
| await expect | ||
| .poll(() => | ||
| videos.evaluateAll((elements: HTMLVideoElement[]) => | ||
| elements.every((video) => video.paused) | ||
| ) | ||
| ) | ||
| .toBe(true) | ||
| await page.emulateMedia({ reducedMotion: 'reduce' }) | ||
| await first.scrollIntoViewIfNeeded() | ||
| // The source is attached (so the frame can show) before playback would have | ||
| // started; asserting `paused` earlier than that proves nothing. | ||
| await expect | ||
| .poll(() => first.evaluate((video: HTMLVideoElement) => video.readyState)) | ||
| .toBeGreaterThanOrEqual(1) | ||
| await expect | ||
| .poll(() => first.evaluate((video: HTMLVideoElement) => video.paused)) | ||
| .toBe(true) | ||
| }) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.