fix: add setDateFnsTzModule for Vite compatibility#6227
Draft
PurkkaKoodari wants to merge 1 commit intoHacker0x01:mainfrom
Draft
fix: add setDateFnsTzModule for Vite compatibility#6227PurkkaKoodari wants to merge 1 commit intoHacker0x01:mainfrom
PurkkaKoodari wants to merge 1 commit intoHacker0x01:mainfrom
Conversation
Add a new exported function `setDateFnsTzModule()` that allows users to provide the date-fns-tz module explicitly. This works around the dynamic `require()` that doesn't work in Vite and other ES module-only bundlers. Fixes Hacker0x01#6204 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Linked issue: #6204
Problem
In some bundlers including Vite, dynamic
require()orrequire()in ES modules doesn't exist. This means thetimeZoneprop will never work in those modes.Changes
Adds a new exported function
setDateFnsTzModule()that allows users to provide thedate-fns-tzmodule explicitly. This works around the dynamicrequire()that doesn't work in Vite and potentially other bundlers (see #6204).While this involves some new global state, one would reasonably expect to set this once within an app. (Problems might arise if an intermediate library attempts to sets this to a version different from the one the root app uses, but that doesn't sound very stable with the dynamic
requireeither.)I might consider adding a
if (dateFnsTzLoadAttempted) throw ...to make sure the function is only called once; however, I didn't commit that addition yet.Screenshots
N/A
To reviewers
Important: In fact, presumably after #6155, I can't get
timeZoneto work even with Webpack and the hello-world application in the repo. I think this might need at least a docs update if this is broken in Webpack as well, hence keeping as draft now. (Also mentioned in #6182 (comment))The diff was mostly written by Claude, but I've reviewed it thoroughly, and the test coverage seems sufficient to me.
Other potential paths for implementation would be significantly harder:
dateFnsTzas a prop - would require significant refactoring todate_utils.tsas it now uses global state.importinstead ofrequirein ES modules - also causes significant challenges, asimportis asynchronous, and now one couldn't necessarily render while the promise is pending.Contribution checklist