Skip to content

Compiler does not handle inline objects #2046

Closed

Description

@esprehn

The compiler will not auto-memo objects created inline in the component, but strong mode also bans using useMemo. This creates very strange helper functions that do nothing except return an object to trigger strong mode memoization.

Octane should either allow useMemo() in strong mode and automatically infer the dependencies, or it should auto-memo the inline objects.

Even if we make the compiler auto memo objects I would also prefer it allow useMemo() in strong mode since that gives authors an explicit way to fix this bug without adding these no-op functions.

ex.

// slow
const context = {
  inline: node.type === "text"
};

<TextContext value={context}>
  ...
</TextContext>

to fix this you have to write:

// magical memo from strong mode.
function makeContext(node) {
  return {
    inline: node.type === "text"
  };
}

const context = makeContext(node);

<TextContext value={context}>
  ...
</TextContext>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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