gpbl / react-day-picker

DayPicker is a customizable date picker component for React. Add date pickers, calendars, and date inputs to your web applications.
https://daypicker.dev
MIT License
6.02k stars 722 forks source link

build: Fix Preact support by externalizing JSX runtime #2076

Closed pwolfert closed 5 months ago

pwolfert commented 6 months ago

Description

When the new jsx transform was introduced, a copy of the JSX runtime started getting included in the index.esm.js bundle. Including this copy meant that we could no longer swap out that module when building our own downstream Preact project. In effect, it broke Preact support.

To fix this, I've updated the rollup config to treat react/jsx-runtime as an external dependency. By externalizing the JSX runtime in this project, it 1) reduces the library bundle size by 32% and 2) allows downstream projects to use whatever JSX runtime they want.

Type of Change

Could possibly be considered a breaking change, but I don't know the landscape of dependent projects well enough to know if that's true.

Checklist

Before submitting your pull request, please make sure the following is done:

Linked Issues

If this PR addresses any existing issues, please link them here. Example: Fixes #123

Test Plan

You can test that it removes the runtime by searching for the jsxDEV function in dist/index.esm.js before and after the change. You can also see that the file size changed from 144KB to 97KB.

I can also create a branch in my downstream project for testing upon request.

gpbl commented 5 months ago

Thanks @pwolfert !

pwolfert commented 5 months ago

Thank you, @gpbl!

eps1lon commented 4 months ago

FYI this is also the correct fix if only react/jsx-runtime would exist. Otherwise library consumers would need to use the React version that was used when publishing this library. Either you declare React as a peer dependency, or inline all its packages. Externalizing some entrypoints while declaring others as peer dependencies only worked incidentally.

pwolfert commented 4 months ago

@eps1lon, maybe I'm not understanding, but it looks like react is a peer dependency of this library, which should mean that react/jsx-runtime should exist, right? Or are you saying it does exist, and so therefore this is the correct fix?

eps1lon commented 4 months ago

Or are you saying it does exist, and so therefore this is the correct fix?

This. Previously you were inlining react/jsx-runtime. Either you inline all entrypoints or none. Just inlining a few (here: just the JSX entrypoint), is bad.

pwolfert commented 4 months ago

Okay cool 😅