Apply badMutable plugin locally
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
While this is not technically a bug, I do believe that this is a very important feature for compatibility with `moment` based libraries.
**Current behavior**
Applying a plugin (using `.extend()`) alters the global `dayjs` constructor. For `dayjs` to be a replacement for `moment` in e.g. third party libraries, it is sometimes necessary to use the `badMutable` plugin.
But when this plugin is applied, whether manually or by some third party code, all `dayjs` instances in the code base suddenly become mutable, which can lead to unexpected behavior and nasty bugs.
**Expected behavior**
It should be possible to apply the `badMutable` plugin locally, to prevent all `dayjs` instances to suddenly become mutable.
By looking at the source code, I couldn't find a way to make this possible.
Any help or suggestions, would be highly appreciated!!
Thanks :D
---
There has been a discussion on this before: #655
And this exact issue has let [`react-day-picker`](https://github.com/gpbl/react-day-picker) (~4.6K ⭐) to stop using dayjs.
Contributor guide
Research direction
Start by reviewing the plugin application path around `.extend()` and the `badMutable` plugin, then read the prior discussion in #655 for constraints and rejected approaches. The work is done when `badMutable` can be applied locally without making unrelated Day.js instances mutable, while preserving compatibility for moment-based libraries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100