Skip to content

Handle route callbacks that reference this during code splitting #8688

Open

Description

@coderabbitai

Summary

Route callbacks that reference this have an existing code-splitting problem. This affects function expressions as well as method-shorthand properties. Address this problem separately from the method-shorthand support in PR #8459.

Requested by @nstepien.

Required changes

  • Establish the supported this contract for route callbacks that can be code-split.
  • Evaluate enforcing this: void in the route callback types, as proposed in the discussion. This is a possible solution, not a predetermined requirement.
  • If type restrictions do not fully address the problem, define appropriate compiler handling or diagnostics for unsupported callbacks.
  • Add regression coverage for function expressions and method-shorthand callbacks that reference this, along with callbacks that do not reference this.
  • Document any resulting callback restrictions.

Affected areas

  • Router code-splitting transforms in packages/router-plugin/src/core/code-splitter/compilers.ts.
  • Route callback type declarations.
  • Router-plugin code-splitter tests.

Rationale

Extracting a callback into a split module must not silently change its supported this behavior. The problem predates method-shorthand support, so it should not block PR #8459.

Acceptance criteria

  • The supported this behavior for split route callbacks is explicit.
  • Unsupported this usage is rejected or diagnosed, or supported usage retains its behavior after code splitting.
  • Regression tests cover both function expressions and method-shorthand callbacks.
  • Callbacks that do not reference this continue to split correctly.

References

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