Handle route callbacks that reference this during code splitting #8688
Send to my agentSummary#
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
thiscontract for route callbacks that can be code-split. - Evaluate enforcing
this: voidin 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 referencethis. - 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
thisbehavior for split route callbacks is explicit. - Unsupported
thisusage 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
thiscontinue to split correctly.
References#
- PR: https://github.com/TanStack/router/pull/8459
- Scope and proposed approach: https://github.com/TanStack/router/pull/8459#issuecomment-6126222720
- Request to create this issue: https://github.com/TanStack/router/pull/8459#issuecomment-6126400534
Sheraff(GitHub profile, opens in a new tab) linked this to #8817
Sign in to join this conversation.