Skip to content

Refactor VideoDemo component for improved responsiveness and styling#276

Merged
yamcodes merged 7 commits intomainfrom
273-regression-demo-video-rendering-too-big-on-mobile
Nov 4, 2025
Merged

Refactor VideoDemo component for improved responsiveness and styling#276
yamcodes merged 7 commits intomainfrom
273-regression-demo-video-rendering-too-big-on-mobile

Conversation

@yamcodes
Copy link
Owner

@yamcodes yamcodes commented Nov 3, 2025

  • Updated the layout of the VideoDemo component to enhance responsiveness by adjusting CSS classes.
  • Modified the button to include an aspect ratio style for better scaling.
  • Improved the fallback image handling with new attributes for responsive loading.
  • Enhanced test coverage for the VideoDemo component, ensuring correct dimensions and styles are applied.

Closes #273

Summary by CodeRabbit

  • New Features

    • Tighter responsive spacing and padding on small screens; centered media container with max width.
    • Media elements (video and image fallback) now use fill-based containment, responsive sizing, and object-contain behavior.
    • Call-to-action buttons now fill available width and enforce a stable aspect ratio.
  • Tests

    • Added end-to-end responsive suite across mobile and large viewports.
    • Updated unit tests for media fallback, video error handling, button styling, and responsive behavior.

- Updated the layout of the VideoDemo component to enhance responsiveness by adjusting CSS classes.
- Modified the button to include an aspect ratio style for better scaling.
- Improved the fallback image handling with new attributes for responsive loading.
- Enhanced test coverage for the VideoDemo component, ensuring correct dimensions and styles are applied.
@yamcodes yamcodes linked an issue Nov 3, 2025 that may be closed by this pull request
@vercel
Copy link

vercel bot commented Nov 3, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
arkenv Ready Ready Preview Comment Nov 4, 2025 5:46pm

@changeset-bot
Copy link

changeset-bot bot commented Nov 3, 2025

⚠️ No Changeset found

Latest commit: 7098847

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added www Improvements or additions to arkenv.js.org tests This issue or PR is about adding, removing or changing tests labels Nov 3, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 3, 2025

Walkthrough

Reworks VideoDemo layout to a centered, max-width full-width wrapper; BackgroundVideo now fills its container (absolute inset-0 w-full h-full) and falls back to a next/image rendered in fill mode with sizes and object-contain. Tests updated and a new Playwright suite validates responsive scaling, fallback, and aspect-ratio behavior.

Changes

Cohort / File(s) Summary
Video Demo component + tests
apps/www/components/page/video-demo.tsx, apps/www/components/page/video-demo.test.tsx
Container switched to centered full-width wrapper with max-width and padding; demo button set to w-full with explicit inline aspect-ratio; BackgroundVideo uses absolute inset-0 w-full h-full (no width/height); fallback Image moved to fill, object-contain, and sizes. Tests/mocks updated to support fill/sizes, forward props/onError, adjust class assertions, remove width checks, and add fallback/error assertions.
Home page layout tweak
apps/www/app/(home)/page.tsx
Adjusted wrapper spacing: removed base mt-4 and sm:px-8, retained sm:mt-8 and changed sm:px-2.
Playwright responsive tests
tooling/playwright-www/tests/responsive.test.ts
New E2E tests across multiple mobile and desktop viewports: ensure no horizontal scroll, media bounding boxes fit viewport (with padding allowance), presence of object-contain, absence of fixed width classes when video present, aspect-ratio preserved across resizes (10% tolerance), and media width capped on large viewports.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Page as Home Page
    participant Demo as VideoDemo
    participant Video as BackgroundVideo
    participant Image as NextImageFallback

    Page->>Demo: render()
    Demo->>Video: mount (class: absolute inset-0 w-full h-full)
    alt video loads successfully
        Video-->>Demo: playing
    else video load/error
        Video-->>Demo: onError
        Demo->>Image: render fallback (fill=true, sizes provided, object-contain)
        Image-->>Demo: loaded
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Review focus:
    • apps/www/components/page/video-demo.tsx — inline aspect-ratio enforcement, removal of width/height props, fill Image usage, and CSS/class changes.
    • apps/www/components/page/video-demo.test.tsx — updated mocks for next/image and next-video, new assertions for data-fill/sizes, and error-fallback simulation.
    • tooling/playwright-www/tests/responsive.test.ts — viewport iteration, bounding-box math, tolerances for flakiness.

Possibly related PRs

  • Fix hero demo #257 — modifies BackgroundVideo/Image usage and updates tests/mocks; directly related to rendering and prop/positioning changes.
  • Fallback to demo gif on mp4 load failure #256 — addresses video load failure handling and fallback tests; closely connected to onError/fallback behavior here.
  • Skeleton #191 — earlier changes to video sizing/poster attributes; touches the same sizing concerns reversed/adjusted by this PR.

Poem

🐰 I nudged the demo snug and neat,
no scroll, no overflow to meet.
If the video trips, an image hops in,
centered, scaled — a tidy win.
Hop, hop — the UI fits! 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: refactoring the VideoDemo component with focus on responsiveness and styling improvements.
Linked Issues check ✅ Passed The PR successfully addresses all requirements from issue #273: video now scales responsively on mobile, layout uses max-width constraints, and new responsive tests verify correct scaling and prevent regressions.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the video rendering regression: page layout adjustments, VideoDemo component refactoring, test updates, and new responsive test suite are all necessary to address the issue.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 273-regression-demo-video-rendering-too-big-on-mobile

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

- Removed unnecessary line breaks in the className assignment for the VideoDemo component in the test file.
- Improved code readability by consolidating the className logic into a single line.
- Changed the padding class from "sm:px-0" to "sm:px-8" to enhance the layout on small screens.
- This adjustment aims to improve the overall responsiveness of the VideoDemo component in tests.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6553928 and 6d7fc2c.

📒 Files selected for processing (4)
  • apps/www/app/(home)/page.tsx (1 hunks)
  • apps/www/components/page/video-demo.test.tsx (9 hunks)
  • apps/www/components/page/video-demo.tsx (1 hunks)
  • tooling/playwright-www/tests/responsive.test.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.test.ts

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.test.ts: Place tests alongside source files and use the .test.ts suffix (e.g., create-env.test.ts, types.test.ts, errors.test.ts, utils.test.ts)
Use Vitest's describe/it structure in tests
Test both success and failure cases for environment validation and utilities
Mock process.env to cover different environment scenarios in tests
In tests, save and restore process.env in setup/teardown (beforeEach/afterEach) to avoid leakage between cases
Verify both runtime behavior and TypeScript types in tests

Files:

  • tooling/playwright-www/tests/responsive.test.ts
🧠 Learnings (1)
📚 Learning: 2025-09-12T06:23:45.463Z
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-12T06:23:45.463Z
Learning: Applies to **/*.test.ts : Use Vitest's describe/it structure in tests

Applied to files:

  • apps/www/components/page/video-demo.test.tsx
🧬 Code graph analysis (2)
tooling/playwright-www/tests/responsive.test.ts (1)
tooling/playwright-www/tests/homepage.test.ts (3)
  • test (4-205)
  • page (185-200)
  • page (168-183)
apps/www/components/page/video-demo.test.tsx (1)
apps/www/components/page/video-demo.tsx (1)
  • VideoDemo (11-59)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test-e2e (e2e)
  • GitHub Check: test-e2e (a11y)
🔇 Additional comments (12)
apps/www/components/page/video-demo.tsx (3)

29-32: Good use of aspect ratio for responsive scaling.

The inline aspectRatio style combined with w-full ensures the button maintains its proportions while scaling responsively. This directly addresses the mobile rendering issue from #273.


53-53: LGTM: Absolute positioning enables proper containment.

The absolute inset-0 w-full h-full classes combined with object-contain ensure the video fills the button container while maintaining aspect ratio, which is exactly what's needed for responsive behavior.


25-25: Review comment is based on incorrect CSS padding assumptions.

CSS padding on nested elements does not stack or add together. The parent container's sm:px-2 padding and the child VideoDemo's sm:px-8 padding are applied independently to each element's own content—they do not sum to sm:px-10. Each element receives its own padding value without affecting the other. No layout issue exists here.

Likely an incorrect or invalid review comment.

apps/www/app/(home)/page.tsx (1)

43-43: Verify cumulative padding with VideoDemo component.

The sm:px-2 padding here stacks with the sm:px-8 padding in the VideoDemo component (line 25 of video-demo.tsx), resulting in a total of sm:px-10 horizontal padding. Confirm this cumulative padding provides the desired layout.

tooling/playwright-www/tests/responsive.test.ts (3)

14-39: Good coverage of mobile viewports.

Testing across multiple mobile viewports (iPhone SE, iPhone 12 Pro, Galaxy S21, Small Mobile) and verifying no horizontal scrolling directly validates the fix for issue #273.


93-128: Robust aspect ratio validation across viewport sizes.

The 5% tolerance for aspect ratio differences when resizing from desktop to mobile is appropriate and will catch regressions where the video doesn't scale proportionally.


130-149: Maximum width constraint validated correctly.

Testing that the video doesn't exceed 810px on large screens (with margin for sub-pixel rendering) directly validates the max-w-[800px] constraint from the component.

apps/www/components/page/video-demo.test.tsx (5)

18-46: Well-structured Image mock for fill mode testing.

The mock correctly handles the fill prop by omitting width/height when fill is true and adding a data-fill attribute for test assertions. This allows the tests to verify the responsive image behavior.


48-85: BackgroundVideo mock matches component implementation.

The default className absolute inset-0 w-full h-full object-contain correctly mirrors the actual component (line 53 of video-demo.tsx), ensuring tests validate the real rendering behavior.


300-322: Comprehensive error fallback testing.

The test correctly verifies that when the video fails, the component switches to the fallback image with proper attributes (data-fill, object-contain, and correct src). This validates the error handling path.


345-351: Aspect ratio enforcement validated correctly.

The test correctly verifies that the button has the inline aspectRatio style matching the WIDTH/HEIGHT constants, which is critical for maintaining proportions across different viewport sizes.

As per coding guidelines


353-368: Responsive image loading validated.

The test confirms that the fallback image includes the sizes attribute for responsive loading and the data-fill attribute indicating fill mode, which aligns with Next.js Image optimization best practices.

- Removed width and height attributes from the Image component in VideoDemo for better responsiveness.
- Updated responsive test assertions to ensure the presence of the 'object-contain' class and to check for responsive width/height classes, enhancing the overall test coverage for the VideoDemo component.
- Updated the responsive design tests to focus on the video element instead of fallback images, ensuring visibility checks and class assertions are more accurate.
- Enhanced aspect ratio tests by verifying dimensions on a container button rather than the media element, improving test reliability.
- Adjusted tolerance for aspect ratio comparisons to account for browser rendering differences.
- Updated the responsive design tests to focus on the button's aspect-ratio style and visibility, improving the accuracy of responsiveness checks.
- Added assertions for the button's class and style attributes to ensure proper responsive behavior.
- Included optional checks for the video element's classes, ensuring that responsiveness is maintained even if the video is not present.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
tooling/playwright-www/tests/responsive.test.ts (4)

69-70: Consider extracting the padding allowance as a named constant.

The hardcoded value 32 represents padding/margins but lacks context. Extracting it would improve readability.

Apply this diff:

+	// Padding/margin allowance for responsive layout
+	const PADDING_ALLOWANCE = 32;
+
 	test.describe("Demo Video Responsiveness", () => {
 		for (const viewport of mobileViewports) {

Then update line 70:

-					const maxAllowedWidth = viewport.width - 32;
+					const maxAllowedWidth = viewport.width - PADDING_ALLOWANCE;

102-102: Replace non-deterministic timeout with deterministic wait.

Using waitForTimeout is discouraged in Playwright tests as it introduces flakiness. Consider waiting for a specific condition instead.

Apply this diff:

 			if (videoCount > 0) {
-				await page.waitForTimeout(500); // Wait for video to load
+				await videoElement.waitFor({ state: "visible" });
 				const videoClass = await videoElement.getAttribute("class");

139-139: Replace arbitrary timeout with deterministic wait.

Using waitForTimeout after resize introduces flakiness. Wait for the layout to stabilize by checking element state instead.

Apply this diff:

 			// Resize to mobile
 			await page.setViewportSize({ width: 375, height: 667 });
-			await page.waitForTimeout(500); // Wait for resize to settle
+			await containerButton.waitFor({ state: "visible" });

172-174: Update comment to match assertion value.

The comment states "natural maximum width (800px)" but the assertion checks for 810px. This inconsistency could confuse future maintainers.

Apply this diff:

 			if (boundingBox) {
-				// Video should not exceed its natural maximum width (800px)
-				// Allow a small margin for sub-pixel rendering
+				// Video should not exceed its natural maximum width (800px + 10px margin for sub-pixel rendering)
 				expect(boundingBox.width).toBeLessThanOrEqual(810);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 50ac98f and 7098847.

📒 Files selected for processing (1)
  • tooling/playwright-www/tests/responsive.test.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.test.ts

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.test.ts: Place tests alongside source files and use the .test.ts suffix (e.g., create-env.test.ts, types.test.ts, errors.test.ts, utils.test.ts)
Use Vitest's describe/it structure in tests
Test both success and failure cases for environment validation and utilities
Mock process.env to cover different environment scenarios in tests
In tests, save and restore process.env in setup/teardown (beforeEach/afterEach) to avoid leakage between cases
Verify both runtime behavior and TypeScript types in tests

Files:

  • tooling/playwright-www/tests/responsive.test.ts
🧠 Learnings (1)
📚 Learning: 2025-09-12T06:23:45.463Z
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-12T06:23:45.463Z
Learning: Applies to **/*.test.ts : Verify both runtime behavior and TypeScript types in tests

Applied to files:

  • tooling/playwright-www/tests/responsive.test.ts
🧬 Code graph analysis (1)
tooling/playwright-www/tests/responsive.test.ts (1)
tooling/playwright-www/tests/homepage.test.ts (3)
  • test (4-205)
  • page (185-200)
  • page (168-183)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test-e2e (a11y)
  • GitHub Check: test-e2e (e2e)

@yamcodes yamcodes merged commit 0cffdd8 into main Nov 4, 2025
15 checks passed
@yamcodes yamcodes deleted the 273-regression-demo-video-rendering-too-big-on-mobile branch November 4, 2025 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests This issue or PR is about adding, removing or changing tests www Improvements or additions to arkenv.js.org

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: demo video rendering too big on mobile

1 participant