Skip to content

Conversation

@ccombe
Copy link

@ccombe ccombe commented Nov 10, 2025

Summary

This PR upgrades react-arborist to be compatible with react-dnd v16 and react-dnd-html5-backend v9, which are ESM-only packages.

Changes

Dependencies

  • Upgraded react-dnd from ^14.0.3 to ^16.0.0
  • Upgraded react-dnd-html5-backend from ^14.0.3 to ^9.0.0

Code Changes

  • src/components/provider.tsx: Updated HTML5Backend import from named to default export (v9 API change)
  • src/components/provider.tsx: Updated DndProvider usage to pass backend class directly with options (v16 API)

Build Configuration

  • package.json: Added exports field to help bundlers choose ESM vs CommonJS builds
  • jest.config.js: Added babel-jest and @babel/preset-env to transform ESM modules for Jest compatibility
  • jest.config.js: Updated transformIgnorePatterns to include react-dnd packages and nested dependencies
  • Added dev dependencies: @babel/core, @babel/preset-env, babel-jest

Showcase App Updates

  • next.config.js: Added transpilePackages to transpile react-arborist from source
  • next.config.js: Configured webpack to prefer ESM build (module field)
  • pages/_document.tsx: Removed viewport meta tag (moved to _app.tsx per Next.js best practices)

Testing

✅ All tests pass (yarn test)
✅ TypeScript compilation succeeds (yarn build)
✅ No linting errors
✅ Showcase app runs successfully
✅ Backwards compatible - all existing APIs remain unchanged

Backwards Compatibility

This upgrade maintains full backwards compatibility:

  • All public APIs (TreeProps, TreeApi, hooks) remain unchanged
  • No breaking changes to the library's external interface
  • Only internal implementation updated for v16/v9 compatibility
  • Library builds both CommonJS (dist/main) and ESM (dist/module) outputs as before

Notes

  • react-dnd v16 is ESM-only, requiring Jest configuration updates for test compatibility
  • The exports field in package.json ensures bundlers use the correct build format
  • Next.js showcase app configured to transpile and use ESM build for compatibility

- Upgrade react-dnd from ^14.0.3 to ^16.0.0
- Upgrade react-dnd-html5-backend from ^14.0.3 to ^9.0.0
- Update HTML5Backend import to default export (v9 API change)
- Update DndProvider usage for v16 API compatibility
- Add Jest configuration for ESM module support (babel-jest)
- Add exports field to package.json for proper ESM/CommonJS resolution
- Update Next.js config to transpile react-arborist and prefer ESM build
- Fix viewport meta tag warning in _document.tsx

All tests pass and TypeScript compilation succeeds. Maintains full backwards compatibility.
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.

1 participant