-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Check that this is really a bug
- I confirm
Reproduction link
https://gist.github.com/TomiBelan/3f130739f8f5ac5deaecaeec49e904f6
Bug description
React-big-calendar has a runtime dependency on dayjs. If you compile an app using react-big-calendar with webpack, the minified bundle will always contain code from dayjs, even if you use a different localizer. The whole point of pluggable localizers is allowing users to choose which datetime library they want to depend on, so this is kind of unfortunate. The dayjs code is ignored at runtime and it just uselessly bloats the bundle size downloaded and parsed by browsers.
It happens because dist/react-big-calendar.esm.js imports some dayjs plugins, and webpack wasn't able to recognize the plugin code is side-effect-free and safe to remove.
Luckily, dayjs is a very small library. In practice it's not a big deal. This is a low priority issue.
Some ideas
- Revisit the decision in feat: Dayjs localizer #2264 to automatically load dayjs plugins. One fix is to stop doing that, and tell the user which plugins they must load themselves. But it is a compatibility break...
- Another possible idea might be to change dist/react-big-calendar.esm.js so that it imports "dayjs/esm/plugin/foo" instead of "dayjs/plugin/foo". Apparently webpack recognizes the esm version has no side effects. But it might need some RBC build system hackery. dist/react-big-calendar.esm.js should import "dayjs/esm/plugin/foo" but lib/localizers/dayjs.js should still require("dayjs/plugin/foo") like before, in order to not break server-side node.js scripts doing require("react-big-calendar"). (There might be a better way but I'm not all that familiar with node.js's ESM support.)
Expected Behavior
Webpack output bundle should contain dayjs code only if you use the dayjs localizer.
Actual Behavior
Webpack output bundle always contains dayjs code (specifically dayjs plugins).
react-big-calendar version
1.6.9
React version
18.2.0
Platform/Target and Browser Versions
Chrome
Validations
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
- Make sure this is a react-big-calendar issue and not an implementation issue
Would you like to open a PR for this bug?
- I'm willing to open a PR