Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions actions/build/scripts/capture-screenshots/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,45 @@ describe("captureScreenshots()", () => {
assert.deepEqual([...image.data.subarray(bottom, bottom + 3)], [255, 0, 0])
}
})
it("captures an app without Controls under a same-origin script policy", async () => {
it("fills both viewports for short root and template pages without Controls under a same-origin script policy", async () => {
const root = await temporaryDirectory()
const screenshots = await temporaryDirectory()
await mkdir(path.join(root, "dist"))
await mkdir(path.join(root, ".github"))
await writeFile(
path.join(root, "dist", "index.html"),
'<!doctype html><html lang="en"><head><meta http-equiv="Content-Security-Policy" content="script-src \'self\'"><title>Fixture</title></head><body><main><h1>Replica</h1></main></body></html>',
'<!doctype html><html lang="en"><head><meta http-equiv="Content-Security-Policy" content="script-src \'self\'"><title>Fixture</title><style>html,body{margin:0;height:100px}</style></head><body><main><h1>Replica</h1></main></body></html>',
)
await writeFile(
path.join(root, ".github/replica.json"),
JSON.stringify({
version: 1,
templates: [
{
id: "settings",
name: "Settings",
category: "Configuration",
description: "Edit settings.",
path: "/settings",
},
],
}),
)

await captureScreenshots(root, screenshots)

const desktop = await readFile(path.join(screenshots, "desktop.png"))
const narrow = await readFile(path.join(screenshots, "narrow.png"))
assert.deepEqual([desktop.readUInt32BE(16), desktop.readUInt32BE(20)], [1440, 900])
assert.deepEqual([narrow.readUInt32BE(16), narrow.readUInt32BE(20)], [390, 844])
for (const directory of ["", "templates/settings"]) {
for (const [name, width, height] of [
["desktop", 1440, 900],
["narrow", 390, 844],
]) {
for (const suffix of ["", "-dark"]) {
const filename = path.join(directory, `${name}${suffix}.png`)
const image = pngjs.PNG.sync.read(await readFile(path.join(screenshots, filename)))
assert.deepEqual([image.width, image.height], [width, height], filename)
}
}
}
})

it("navigates before capture when app boot reads a URL-bound default", async () => {
Expand Down
10 changes: 6 additions & 4 deletions actions/build/scripts/constants.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import viewports from "../../../hub/client/utils/screenshot-viewports/viewports.json" with { type: "json" }

export const ARTIFACT_NAME = "replica-build-v1"
export const SCREENSHOTS_ARTIFACT_NAME = "replica-screenshots-v1"
export const CONTENT_TYPES = {
Expand All @@ -18,7 +20,7 @@ export const MAX_PACKAGE_BYTES = 150 * 1024 * 1024
export const MAX_TEMPLATES = 12
export const MAX_TEMPLATE_MANIFEST_BYTES = 16 * 1024
export const START_ROUTE = "/"
export const VIEWPORTS = [
{ name: "desktop", width: 1440, height: 900 },
{ name: "narrow", width: 390, height: 844 },
]
export const VIEWPORTS = Object.entries(viewports).map(([name, dimensions]) => ({
name,
...dimensions,
}))
3 changes: 2 additions & 1 deletion hub/client/components/prototype-card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Label } from "@primer/react-brand"
import { BuildStateLabel } from "@components/build-state-label"
import { HubUserAvatar } from "@components/hub-user-avatar"
import { ScrollingScreenshot } from "@components/scrolling-screenshot"
import { screenshotViewportStyles } from "@utils/screenshot-viewports"

import type { PrototypeCardData } from "./types"

Expand All @@ -29,7 +30,7 @@ export function PrototypeCard({
<HubUserAvatar src={prototype.author.avatarUrl} size={layout === "gallery" ? 28 : 24} />
)
const preview = (
<div className="prototype-card__preview">
<div className="prototype-card__preview" style={screenshotViewportStyles.desktop}>
{prototype.reviewBuild ? (
<ScrollingScreenshot
src={prototype.reviewBuild.screenshotSrc}
Expand Down
2 changes: 0 additions & 2 deletions hub/client/components/prototype-card/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
position: relative;
background: var(--hub-canvas-muted);
width: 100%;
aspect-ratio: 395 / 280.480255;
flex: none;
overflow: hidden;
border: 1px solid var(--hub-border-muted);
Expand Down Expand Up @@ -148,7 +147,6 @@

.prototype-card--list .prototype-card__preview {
width: 5.25rem;
aspect-ratio: 16 / 10;
border-radius: var(--hub-radius-small);
}

Expand Down
8 changes: 5 additions & 3 deletions hub/client/components/scrolling-screenshot/stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { Decorator, Meta, StoryObj } from "@storybook/react-vite"

import { screenshotViewportStyles } from "@utils/screenshot-viewports"

import {
welcomeFullPageScreenshot,
welcomeNarrowFullPageScreenshot,
Expand Down Expand Up @@ -37,21 +39,21 @@ export default meta
type Story = StoryObj<typeof meta>

export const FullPage: Story = {
decorators: [previewFrame("395 / 280")],
decorators: [previewFrame(screenshotViewportStyles.desktop.aspectRatio)],
}

export const NarrowBuildDetail: Story = {
args: {
alt: "Full-height narrow screenshot of the welcome prototype",
src: welcomeNarrowFullPageScreenshot,
},
decorators: [previewFrame("390 / 844")],
decorators: [previewFrame(screenshotViewportStyles.narrow.aspectRatio)],
}

export const ViewportHeight: Story = {
args: {
alt: "Viewport-height screenshot of the welcome prototype",
src: welcomeScreenshot,
},
decorators: [previewFrame("395 / 280")],
decorators: [previewFrame(screenshotViewportStyles.desktop.aspectRatio)],
}
4 changes: 3 additions & 1 deletion hub/client/components/template-card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { ArrowUpRightIcon, BrowserIcon } from "@primer/octicons-react"
import { ScrollingScreenshot } from "@components/scrolling-screenshot"
import "@components/prototype-card/styles.css"

import { screenshotViewportStyles } from "@utils/screenshot-viewports"

import type { TemplateCardData } from "./types"
import "./styles.css"

Expand All @@ -17,7 +19,7 @@ export function TemplateCard({
}) {
return (
<section className="prototype-card template-card">
<div className="prototype-card__preview">
<div className="prototype-card__preview" style={screenshotViewportStyles.desktop}>
{template.screenshotSrc ? (
<ScrollingScreenshot
src={template.screenshotSrc}
Expand Down
4 changes: 4 additions & 0 deletions hub/client/components/template-card/stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ type Story = StoryObj<typeof meta>

export const Ready: Story = {}

export const Default: Story = {
args: { template: templatesData.templates[0]! },
}

export const FullHeight: Story = {
args: { template: templatesData.templates[2]! },
}
Expand Down
3 changes: 2 additions & 1 deletion hub/client/components/template-picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useEffect, useRef, useState } from "react"
import type { KeyboardEvent } from "react"

import { useOptionalHubTheme } from "@hooks/use-hub-theme"
import { screenshotViewportStyles } from "@utils/screenshot-viewports"

import type { StartingTemplate } from "./types"
import "./styles.css"
Expand Down Expand Up @@ -166,7 +167,7 @@ export function TemplatePicker({
closeOptions()
}}
>
<span className="template-picker__preview">
<span className="template-picker__preview" style={screenshotViewportStyles.desktop}>
{screenshotSrc && !failedScreenshots.includes(screenshotSrc) ? (
<img
src={screenshotSrc}
Expand Down
1 change: 0 additions & 1 deletion hub/client/components/template-picker/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
.template-picker__preview {
display: grid;
width: 4.5rem;
height: 3rem;
flex: none;
overflow: hidden;
place-items: center;
Expand Down
6 changes: 6 additions & 0 deletions hub/client/utils/screenshot-viewports/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import viewports from "./viewports.json"

export const screenshotViewportStyles = {
desktop: { aspectRatio: `${viewports.desktop.width} / ${viewports.desktop.height}` },
narrow: { aspectRatio: `${viewports.narrow.width} / ${viewports.narrow.height}` },
}
4 changes: 4 additions & 0 deletions hub/client/utils/screenshot-viewports/viewports.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"desktop": { "width": 1440, "height": 900 },
"narrow": { "width": 390, "height": 844 }
}
6 changes: 6 additions & 0 deletions hub/docs/github-actions-builds.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ For [standalone private previews](build-previews.md#standalone-private-previews)

If Hub is offline during an update, the workflow can still upload both artifacts to GitHub. GitHub does not automatically retry failed webhook deliveries. Once Hub returns, polling or requested redelivery can import the retained packages. Hub still needs GitHub API and artifact-download access. Recovery is bounded by the three-day artifact retention and polling window; expired packages cannot be recovered automatically. Re-running the workflow is safe because successful Builds and artifacts are never replaced.

### Screenshot dimensions

The [shared viewport settings](../client/utils/screenshot-viewports/viewports.json) define the capture width and minimum height for desktop and narrow screenshots. The build action uses these settings for both capture and package validation. Hub uses the same desktop ratio for prototype cards, template cards, and template-picker thumbnails, so a viewport-height image fills its frame without changing shape. Taller pages retain their full height; prototype and template cards reveal the remaining content on hover, keyboard focus, or manual scrolling.

Change these settings rather than adding independent sizes to workflow YAML or card styles. Capture at least the configured height, not a fixed full-page height. The widths remain part of the versioned artifact contract; changing them also requires updating Hub's import and decision-model consumers. Existing Build images are immutable. To use revised capture settings, pin the prototype workflow's Replica actions to the new implementation commit and push a new Build. Deploy the matching Hub change to update displayed frame ratios.

## Flow

```mermaid
Expand Down
Loading