Skip to content

Production build fails with StateContexts is not defined during prerender in 0.9.2.post1 #6500

@VarYUvrc

Description

@VarYUvrc

Describe the bug
Production build fails in Reflex 0.9.2, 0.9.2.post1 during prerendering with:

ReferenceError: StateContexts is not defined

The generated route file .web/app/routes/_index.jsx references StateContexts:

useContext(StateContexts.some_state_context)

but the same generated file does not import StateContexts from $/utils/context.

In my generated file, the import was:

import {ClientSide, ColorModeContext} from "$/utils/context"

so prerendering / fails.

To Reproduce

  1. Use Reflex 0.9.2.post1.
  2. Create an app with state-dependent components on the index page.
  3. Run:
uv run reflex run --env prod
  1. The production build fails during prerendering with StateContexts is not defined.

The app starts successfully if SSR/prerendering is disabled:

REFLEX_SSR=false uv run reflex run --env prod

Expected behavior

Production build should complete successfully.

If generated route code references StateContexts, the generated route file should import it:

import {ClientSide, ColorModeContext, StateContexts} from "$/utils/context"

When SSR/prerendering is disabled via REFLEX_SSR=false, Reflex should also ensure that the generated React Router config does not attempt to prerender the route.

Screenshots
Not applicable.

Specifics (please complete the following information):

  • Python Version:3.12
  • Reflex Version: 0.9.2.post1
  • OS: Ubuntu 24.04 LTS (WSL2)
  • Package manager: uv

Additional context

As a temporary workaround for users affected by this issue, disabling SSR in rxconfig.py also avoids the production build failure:

import os

os.environ.setdefault("REFLEX_SSR", "false")

This should be placed before Reflex reads the environment configuration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions