Skip to content

feat(rsc): support hoisting with runtime wrapper in transformHoistInlineDirective + add callable use cache example - #1330

Draft
hi-ogawa wants to merge 14 commits into
mainfrom
callable-inline-hoist
Draft

feat(rsc): support hoisting with runtime wrapper in transformHoistInlineDirective + add callable use cache example#1330
hi-ogawa wants to merge 14 commits into
mainfrom
callable-inline-hoist

Conversation

@hi-ogawa

@hi-ogawa hi-ogawa commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

This PR adds hoistRuntime: boolean option to transformHoistInlineDirective, so it allows hoist-exported inline directive functions to have runtime wrapper applied. Still haven't fully verified the exact requirement for use cache in #1246 but this looks like a concrete self-contained step forward with demonstrate-able e2e, so I'm thinking to land this first anyways.

Example:

  • Source
function Component() {
  const x = 1

  async function action(y) {
    'use cache'
    return x + y
  }
}
  • Transformed with hoistRuntime: false (still the default)
function Component() {
  const x = 1
  const action = __RUNTIME__($$hoist_0_action).bind(null, x) // 👈 runtime in reference site
}

export async function $$hoist_0_action(x, y) {
  'use cache'
  return x + y
}
  • Transformed with hoistRuntime: true
function Component() {
  const x = 1
  const action = $$hoist_0_action.bind(null, x)
}

export const $$hoist_0_action = __RUNTIME__($$hoist_0_action$$impl) // 👈 runtime in export site

async function $$hoist_0_action$$impl(x, y) {
  'use cache'
  return x + y
}

Allow inline directive transforms to create one module-level runtime binding while controlling its export independently. Add a callable cache example that verifies the wrapped binding through Server Function transport.

Co-authored-by: OpenCode <noreply@opencode.ai>
@hi-ogawa hi-ogawa changed the title feat(rsc): hoist inline directive runtimes feat(rsc): support hoist with runtime wrapper in transformHoistInlineDirective Jul 27, 2026
@hi-ogawa hi-ogawa changed the title feat(rsc): support hoist with runtime wrapper in transformHoistInlineDirective feat(rsc): support hoist with runtime wrapper in transformHoistInlineDirective to support callable use-cache Jul 27, 2026
@hi-ogawa hi-ogawa changed the title feat(rsc): support hoist with runtime wrapper in transformHoistInlineDirective to support callable use-cache feat(rsc): support hoist with runtime wrapper in transformHoistInlineDirective and callable use-cache example Jul 27, 2026
@hi-ogawa hi-ogawa changed the title feat(rsc): support hoist with runtime wrapper in transformHoistInlineDirective and callable use-cache example feat(rsc): support hoist with runtime wrapper in transformHoistInlineDirective and callable use cache example Jul 27, 2026
@hi-ogawa hi-ogawa changed the title feat(rsc): support hoist with runtime wrapper in transformHoistInlineDirective and callable use cache example feat(rsc): support hoisting with runtime wrapper in transformHoistInlineDirective + add callable use cache example Jul 27, 2026
hi-ogawa and others added 3 commits July 27, 2026 19:04
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Comment thread packages/plugin-rsc/examples/use-cache-callable/src/framework/cache-runtime.ts Outdated
Comment thread packages/plugin-rsc/examples/use-cache-callable/src/root.tsx Outdated
@hi-ogawa
hi-ogawa marked this pull request as draft July 27, 2026 10:17
Co-authored-by: OpenCode <noreply@opencode.ai>
hi-ogawa-agent and others added 6 commits July 28, 2026 12:19
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>
Co-authored-by: OpenCode <noreply@opencode.ai>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: review actual test and example

Co-authored-by: OpenCode <noreply@opencode.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants