Skip to content

feat: v2.0.0 — React 19 only, drop React 15.6 build and forwardRef - #128

Merged
roderickhsiao merged 3 commits into
mainfrom
v2-major
Sep 4, 2026
Merged

roderickhsiao merged 3 commits into
mainfrom
v2-major

Conversation

@roderickhsiao

@roderickhsiao roderickhsiao commented Sep 4, 2026 •

Copy link
Copy Markdown
Owner

Major version bump to 2.0.0. Removes the legacy React 15.6 support path and the forwardRef wrapper.

Breaking changes

Requires React 19 or later. peerDependencies narrows from ^0.14.7 || ^15 || ^16 || ^17 || ^18 || ^19 to >=19.0.0.

  • The React 15.6 build is gone. src/react-15.6/ held a class component whose componentDidUpdate hand-set --aspect-ratio via node.style.setProperty as a fallback for facebook/react#6411 — dead code since React 16 writes custom properties from the style prop natively.
  • The default export changed meaning. It used to resolve to that legacy class; it now points at the same modern component as the named export. Both import AspectRatio from 'react-aspect-ratio' and import { AspectRatio } from 'react-aspect-ratio' keep working and are now identical.
  • forwardRef removed. React 19 passes ref to function components as an ordinary prop, so it rides through ...restProps to the underlying div. No call-site change; the only visible difference is in a type position (ForwardRefExoticComponent<…> → use typeof AspectRatio).

Users on React 18 or older should stay on react-aspect-ratio@1.x — it is unchanged and there is no fix in 2.0 they would be missing.

Other changes

  • Flattened src/react-latest/index.tsx → src/index.tsx; dropped the src/index.ts re-export shim.
  • src/types.ts imports ComponentProps explicitly instead of leaning on the UMD React global.
  • Test files were being shipped in the published build (dist/react-latest/index.test.js) because the babel and tsconfig.publish.json ignore globs pointed at a nonexistent src/__tests__/**. Now excluded properly — dist/ is 2 files per target.
  • @types/react / @types/react-dom → ^19; dropped the unused @types/react-test-renderer.
  • Added MIGRATION.md with the full 1.x → 2.0 guide, linked from the README. README also documents the ref prop and the React 19 requirement.
  • Added a test asserting ref reaches the underlying element, covering the forwardRef removal.

Verification

  • yarn lint — clean
  • yarn tsc --noEmit — clean
  • jest src — 6/6 pass, snapshot unchanged apart from its new path
  • .scripts/prepublish.sh — builds cjs/es/umd/next plus .d.ts cleanly

Follow-up

yarn.lock is untouched in this PR. It is replaced outright by react-aspect-ratio#129, which migrates the repo from yarn to pnpm and is stacked on this branch — merge this one first.

🤖 Generated with Claude Code

BREAKING CHANGE: requires React 19 or later.

- Remove the legacy src/react-15.6 class component and its componentDidUpdate
  custom-property fallback for react/react#6411 (dead code since React 16).
- Flatten src/react-latest into src/index.tsx; the default and named exports are
  now the same component.
- Drop the forwardRef wrapper — React 19 passes ref as a regular prop.
- Narrow peerDependencies to react >=19.0.0 and bump @types/react to ^19.
- Exclude test files from the published build instead of a stale __tests__ glob.
- Add MIGRATION.md and a README migration section.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

README’s new Requirements wording is currently misleading about forwardRef vs React 19’s ref-as-prop behavior, and should be corrected before release.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR bumps react-aspect-ratio to 2.0.0 by making React 19+ the only supported peer, removing the legacy React 15.6 implementation path, and simplifying the public entry point so default and named exports are identical.

Changes:

  • Drop React 15.6 fallback build and remove the forwardRef wrapper in favor of React 19’s ref-as-prop behavior.
  • Flatten the source entry point to src/index.tsx and remove the old src/index.ts shim and src/react-latest/ entry.
  • Tighten publish/build output by excluding test files correctly and update documentation with a migration guide.
File summaries
File Description
tsconfig.publish.json Excludes test files and stories from the publish TS build.
src/types.ts Switches to explicit ComponentProps import for Props.
src/react-latest/index.tsx Removes the previous forwardRef-based implementation.
src/react-latest/snapshots/index.test.tsx.snap Removes snapshot from the old react-latest test location.
src/react-15.6/index.tsx Removes legacy React 15.6 class-component implementation.
src/react-15.6/index.test.tsx Removes tests tied to the legacy React 15.6 build.
src/index.tsx Adds the new unified entry-point component implementation.
src/index.ts Removes the old default/named-export routing shim.
src/index.test.tsx Adds coverage ensuring ref reaches the underlying div.
src/snapshots/index.test.tsx.snap Adds snapshot in the new test snapshot location.
README.md Documents React 19 requirement, migration path, and ref behavior.
package.json Bumps to 2.0.0, narrows React peer range to >=19.0.0, updates React type deps.
MIGRATION.md Adds a 1.x → 2.0 migration guide explaining breaking changes.
.scripts/prepublish.sh Updates Babel ignore globs to exclude test files from dist/.
Review details
  • Files reviewed: 13/14 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread README.md Resolved
Comment thread README.md Resolved
The Requirements section read as though `forwardRef` itself needs React 19.
It does not — `forwardRef` has worked since React 16.3. What React 19 changes
is that `ref` is passed to function components as an ordinary prop, which is
what makes the wrapper unnecessary. Reworded to say that, and to name where
`ref` actually lands (`...restProps` on the underlying div).

MIGRATION.md already stated this correctly, so no change was needed there.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@roderickhsiao

Copy link
Copy Markdown
Owner Author

🤖 Applied. Both README findings were right and are fixed in docs: clarify what React 19 changes about ref, and fix a comma splice:

  • Requirements wording — forwardRef is not React 19+; it has worked since 16.3. What React 19 changes is ref being passed to function components as an ordinary prop, which is what makes the wrapper unnecessary. Reworded, and it now names where ref lands (...restProps on the underlying div).
  • Comma splice — split with a semicolon.

Consistency sweep: MIGRATION.md already stated the React 19 behaviour correctly, so the README was the only site carrying the misleading version.

The workflow filtered pull_request on branches: [main], so a PR stacked on
another feature branch got no build at all — it could merge into its parent
entirely untested. Widened to all pull requests; push stays on main.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@roderickhsiao
roderickhsiao merged commit 86567ff into main Sep 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants