Skip to content

Bug: ops.ctx is undefined despite __ctx__ definition #1

Description

@iDevo-ll

Bug: ops.ctx is undefined inside action execution despite __ctx__ definition

Description

According to the FractoState documentation, actions exposed through __ctx__ should be accessible via ops.ctx.

However, when an action attempts to access a method exposed by __ctx__, ops.ctx is undefined, causing a runtime crash.

Error

Uncaught TypeError: Cannot read properties of undefined (reading 'getTitle')

at store/meta.ts:42:24

return ops.ctx.getTitle(docsConfig, pathname);

Reproduction

export const MetaFlow = defineFlow(
  "meta",
  initialState,
  {
    actions: {
      __ctx__(c) {
        return {
          getTitle: (docsConfig: any[], pathname: string) => {
            const actions = c.actions;
            const title = actions.findTitleInConfig(
              docsConfig,
              pathname
            );

            return title;
          },
        };
      },

      getDTitle: () => (ops) => {
        const pathname =
          typeof window !== "undefined"
            ? window.location.pathname
            : "";

        return ops.ctx.getTitle(
          docsConfig,
          pathname
        );
      },

      findTitleInConfig: (items: any[], path: string) => (ops) => {
        // implementation omitted
      },
    },
  }
);

Expected behavior

ops.ctx should contain the object returned by __ctx__.

Example:

ops.ctx.getTitle(...)

should execute successfully.

Actual behavior

ops.ctx is undefined:

TypeError:
Cannot read properties of undefined (reading 'getTitle')

Environment

  • FractoState version: latest
  • React
  • Next.js
  • Client Component ("use client")

Additional notes

The documentation appears to indicate that __ctx__ values are exposed through ops.ctx, so either:

  1. __ctx__ is not being initialized correctly for action execution.
  2. ops.ctx is unavailable in certain execution contexts.
  3. The documentation is outdated and another API should be used.

Could you clarify the intended usage of __ctx__ and whether ops.ctx should be available inside actions and effects?

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