Migrate react-moment to 2.0.2 - #7006
Conversation
Greptile SummaryThe PR migrates the Moment component to
Confidence Score: 5/5The PR appears safe to merge because no blocking failure remains in the reviewed follow-up scope. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| packages/reflex-components-moment/src/reflex_components_moment/moment.py | Upgrades react-moment, widens the trim and parse contracts, and conditionally imports duration-format support; no eligible follow-up defect was established. |
| tests/integration/test_moment.py | Adds browser-level regression coverage for the migrated parsing and duration-format behavior. |
| tests/units/compiler/test_memoize_plugin.py | Verifies generated props and dependency imports for the updated Moment component. |
| docs/app/reflex.lock/package.json | Updates the generated frontend manifest to react-moment 2.0.2. |
| docs/app/reflex.lock/bun.lock | Regenerates the Bun lockfile for the react-moment dependency upgrade. |
Reviews (9): Last reviewed commit: "Make Moment duration dependency conditio..." | Re-trigger Greptile
Merging this PR will not alter performance
Comparing Footnotes
|
6ab85d3 to
f18753f
Compare
There was a problem hiding this comment.
All reported issues were addressed across 7 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Remove a blank line after a docstring flagged by ruff, assert the widened trim/parse props through render() so the assertion type-checks against the generated stub, and regenerate the stale moment.pyi hash. Claude-Session: https://claude.ai/code/session_01MoV7fVgzsa5dRLRzFZU9s8
FarhanAliRaza
left a comment
There was a problem hiding this comment.
Request changes
This PR breaks the duration and duration_from_now props of rx.moment.
Cause
react-moment 1.2.2 bundles moment-duration-format inside its own dist file. react-moment 2.0.2 removes it. Version 2.0.2 loads the plugin with a require() call. A bundler replaces that call with a stub in an ESM build. The load fails without a message. The plugin never patches moment. The component then throws:
Error: [react-moment] Duration formatting requires moment-duration-format.
Install the `moment-duration-format` package and ensure it is loaded before
using the `duration` or `durationFromNow` props.
React unwinds to the error boundary. The complete page fails. The failure is not limited to the moment element.
Evidence
I built an app with nine rx.moment variants. I ran the same app on main and on this branch. I changed only the library version.
| Props | main (1.2.2) |
This PR (2.0.2) |
|---|---|---|
format="YYYY-MM-DD" |
2026-08-30 |
page crash |
parse="DD-MM-YYYY" |
2026-08-30 |
page crash |
parse=["YYYY-MM-DD", "DD-MM-YYYY"] |
2026-08-30 |
page crash |
duration=... |
5 hrs 30 mins |
page crash |
trim=True |
5 hrs 0 mins |
page crash |
trim="large" |
30 mins |
page crash |
main renders all cases. This branch renders none.
Fix
lib_dependencies installs the package. It does not import it. Add the import in add_imports(). Use the same pattern as tz.
from reflex_base.utils.imports import ImportDict, ImportVar
def add_imports(self) -> ImportDict:
...
if self.tz is not None:
imports["moment-timezone@0.6.2"] = ""
if self.duration is not None or self.duration_from_now is not None:
imports["moment-duration-format@2.2.2"] = ImportVar(tag=None)
return importsUse ImportVar(tag=None). Do not use "". An empty tag collides with the moment-timezone import. The compiler then fails:
ValueError: Can not compile, the tag is used multiple time from
moment-timezone@0.6.2 and moment-duration-format@2.2.2
I applied this patch on the PR head. All nine cases render. reflex export --no-zip succeeds. The production bundle contains the plugin. The 121 unit tests pass. The browser console is clean.
Also required
Add a duration case to the integration test. The current test cannot detect this failure. See the inline comments.
There was a problem hiding this comment.
All reported issues were addressed across 3 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
Narrow `parse` from `Var[str | list[Any]]` to `Var[str | list[str]]` to
match react-moment's `MomentFormatSpecification`, which is a format string
or a list of format strings. This drops the now-unused `Any` import.
Document the widened forms of both props that this migration enables:
`trim` also accepts a trim template ("large", "small", "both", "all",
"final", "left", "right"), and `parse` also accepts a list of formats to
try. Regenerate the Moment stub hash.
Summary
Migrates rx.moment from react-moment@1.2.2 to react-moment@2.0.2.
Changes
Testing
Related issue: #7003