Skip to content

fix(presetSuggestion): use orientation-aware fallback for non-standard aspect ratios#883

Open
rahul-rajak-nsut wants to merge 3 commits into
magic-peach:mainfrom
rahul-rajak-nsut:fix/custom-preset-dimension-validation
Open

fix(presetSuggestion): use orientation-aware fallback for non-standard aspect ratios#883
rahul-rajak-nsut wants to merge 3 commits into
magic-peach:mainfrom
rahul-rajak-nsut:fix/custom-preset-dimension-validation

Conversation

@rahul-rajak-nsut
Copy link
Copy Markdown
Contributor

@rahul-rajak-nsut rahul-rajak-nsut commented May 21, 2026

Description

Fixes a logic bug in suggestPreset() where the fallback for unrecognised aspect ratios always returned "vertical-9-16" (portrait) regardless of whether the video was actually wide or tall.

A single orientation check is added to the fallback: width >= height returns "landscape-16-9", otherwise "vertical-9-16". Common landscape formats like 16:10, 4:3, and 3:2 now correctly suggest a landscape preset instead of portrait.

The existing test that was asserting the wrong behavior is also corrected, and two new test cases are added for both landscape and portrait fallback paths.

Related Issue

Closes #880

Type of Contribution

  • Bug fix
  • New feature
  • Documentation update
  • GSSoC contribution

Participant Info

  • GitHub username: @rahul-rajak-nsut
  • Contribution level (Beginner/Intermediate/Advanced): Intermediate

Screen Recording

Not applicable — this PR contains no UI or visual changes. The fix is entirely within a pure TypeScript utility function (src/lib/presetSuggestion.ts) and its test file. No component, style, or DOM element was modified.

Changes made

src/lib/presetSuggestion.ts — one-line fix:

- return "vertical-9-16";
+ // Orientation-aware fallback: wide videos → landscape, tall videos → portrait
+ return width >= height ? "landscape-16-9" : "vertical-9-16";

src/lib/tests/presetSuggestion.test.ts — fixed the wrong test, added coverage:

- it("falls back to vertical 9:16 when no close ratio matches", () => {
-   expect(suggestPreset(1440, 900)).toBe("vertical-9-16");
- });
+ it("falls back to landscape-16-9 for wide videos that don't closely match 16:9", () => {
+   expect(suggestPreset(1440, 900)).toBe("landscape-16-9");  // 16:10
+   expect(suggestPreset(1024, 768)).toBe("landscape-16-9");  // 4:3
+   expect(suggestPreset(1280, 800)).toBe("landscape-16-9");  // 16:10
+ });
+
+ it("falls back to vertical-9-16 for tall videos that don't closely match 9:16", () => {
+   expect(suggestPreset(900, 1440)).toBe("vertical-9-16");   // 10:16
+   expect(suggestPreset(768, 1024)).toBe("vertical-9-16");   // 3:4
+ });

Checklist

  • I have read the contribution guidelines
  • My changes follow the project structure
  • I have tested my changes in Chrome, Firefox, and Safari
  • bun run lint passes (no ESLint errors)
  • bunx tsc --noEmit passes (no TypeScript errors)
  • New interactive elements have aria-label / accessible names — N/A, no UI changes
  • No console.log statements left in
  • This PR is related to a valid issue
  • Screen recording attached above — N/A, no UI/visual changes

- Validate width/height in handleWidthChange and handleHeightChange
- Reject values outside 16–7680 range and NaN before updating state
- Add autoComplete='off' to width and height inputs

Fixes magic-peach#24
…d ratios

Previously, any video that didn't closely match 9:16, 16:9, or 1:1
always fell back to 'vertical-9-16' (portrait), regardless of actual
orientation. A 1440x900 (16:10) landscape video would be suggested a
portrait preset.

Fix the fallback to check width vs height:
- wide videos (width >= height) → 'landscape-16-9'
- tall videos (height < width)  → 'vertical-9-16'

Also updates the test that was encoding the wrong behavior as expected,
and adds coverage for 4:3 and 16:10 landscape/portrait inputs.

Fixes magic-peach#880
@vercel
Copy link
Copy Markdown

vercel Bot commented May 21, 2026

@rahul-rajak-nsut is attempting to deploy a commit to the magic-peach1's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link
Copy Markdown
Contributor

👋 Thanks for your PR, @rahul-rajak-nsut!

Welcome to Reframe — a browser-based video editor built for everyone 🎬

🟠 GSSoC'26 PR detected — thanks for contributing under GirlScript Summer of Code 2026!

What happens next

  1. 🤖 Automated checks — build & TypeScript typecheck will run automatically
  2. Vercel preview — a preview deployment will be created (requires maintainer authorization for fork PRs)
  3. 👀 Code review — a maintainer will review your changes
  4. 🚀 Merge — once approved, your PR will be merged!

Quick checklist

  • PR title follows Conventional Commits (e.g. feat: add dark mode)
  • Linked the issue this PR closes (e.g. Closes #123)
  • Tested the changes locally (bun run dev)
  • Build passes (bun run build)

Useful links

Happy coding! 🎉

@github-actions github-actions Bot added the level:beginner Beginner level - 20 pts label May 21, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

✅ PR Format Check Passed — @rahul-rajak-nsut

Basic format checks passed. A maintainer will review your code changes.

This does not mean the PR is approved — it just means the format is correct.

@github-actions github-actions Bot added type:bug Bug fix type:design UI/UX design type:docs Documentation type:feature New feature type:testing Testing gssoc'26 GirlScript Summer of Code 2026 labels May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc'26 GirlScript Summer of Code 2026 level:beginner Beginner level - 20 pts type:bug Bug fix type:design UI/UX design type:docs Documentation type:feature New feature type:testing Testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] suggestPreset() falls back to portrait (vertical-9-16) for landscape videos that don't exactly match 16:9

1 participant