Skip to content

Migrate react-moment to 2.0.2 - #7006

Open
harsh21234i wants to merge 8 commits into
reflex-dev:mainfrom
harsh21234i:fix/7003-moment-migration
Open

Migrate react-moment to 2.0.2#7006
harsh21234i wants to merge 8 commits into
reflex-dev:mainfrom
harsh21234i:fix/7003-moment-migration

Conversation

@harsh21234i

@harsh21234i harsh21234i commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Migrates rx.moment from react-moment@1.2.2 to react-moment@2.0.2.

Changes

  • Added moment-duration-format@2.2.2.
  • Updated trim to support boolean and string values.
  • Updated parse to support string and list values.
  • Regenerated Moment type metadata and lockfiles.
  • Added unit and integration regression tests.
  • Confirmed compatibility in both development and production modes.

Testing

  • 121 passed unit tests
  • 2 passed integration tests
  • Ruff formatting and lint checks passed
  • Lockfile and generated metadata validation passed

Related issue: #7003

Review in cubic

@harsh21234i
harsh21234i requested review from a team and Alek99 as code owners August 30, 2026 15:28
@greptile-apps

greptile-apps Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR migrates the Moment component to react-moment 2.0.2 and updates its supported prop types and duration-format integration.

  • Upgrades the generated frontend dependency and lockfile entries.
  • Adds conditional loading of moment-duration-format for duration rendering.
  • Adds unit and integration regression coverage and refreshes generated metadata.

Confidence Score: 5/5

The PR appears safe to merge because no blocking failure remains in the reviewed follow-up scope.

No blocking failure remains.

Important Files Changed

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

@codspeed-hq

codspeed-hq Bot commented Aug 30, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 32 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing harsh21234i:fix/7003-moment-migration (6c2b528) with main (9a26753)

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 7 files

Re-trigger cubic

@harsh21234i
harsh21234i force-pushed the fix/7003-moment-migration branch from 6ab85d3 to f18753f Compare August 30, 2026 15:57

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 7 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread tests/integration/test_moment.py Outdated
harsh21234i and others added 2 commits August 30, 2026 21:41
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 FarhanAliRaza left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 imports

Use 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.

Comment thread packages/reflex-components-moment/src/reflex_components_moment/moment.py Outdated
Comment thread tests/integration/test_moment.py Outdated
Comment thread tests/units/compiler/test_memoize_plugin.py Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread tests/integration/test_moment.py Outdated
harsh21234i and others added 2 commits September 1, 2026 14:58
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.
FarhanAliRaza
FarhanAliRaza previously approved these changes Sep 1, 2026
Comment thread packages/reflex-components-moment/src/reflex_components_moment/moment.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants