Skip to content

fix(web): preserve callable function properties - #506

Open
kings0x wants to merge 1 commit into
Openpanel-dev:mainfrom
kings0x:fix/nextjs-turbopack-window-op-call
Open

kings0x wants to merge 1 commit into
Openpanel-dev:mainfrom
kings0x:fix/nextjs-turbopack-window-op-call

Conversation

@kings0x

@kings0x kings0x commented Sep 15, 2026

Copy link
Copy Markdown

Fixes #240

Summary

Next.js 15.5 with Turbopack transforms optional calls such as:

window.op?.('track', ...)

into a call through window.op.call(...).

The callable window.op Proxy only resolved properties from the OpenPanel
instance, so native Function properties such as .call returned undefined.

This change:

  • Falls back to properties from the callable Proxy target.
  • Preserves .call, .apply, .bind, and other native Function behavior.
  • Handles the same behavior in the pre-load queue snippet.
  • Adds regression coverage for Turbopack-style calls.
  • Preserves the existing callable and property-style APIs.

Verification

Reproduced before the fix using the provided Next.js 15.5.7 Turbopack app:

Error: _window_op.call is not a function

After the fix, the same browser interaction completes without the error.

Also verified:

  • 3 regression tests pass
  • TypeScript typecheck passes
  • Web SDK production bundle builds
  • Next.js 15.5.7 production build passes
  • Tests pass under the repository-pinned Node.js 24.19.0

Summary by CodeRabbit

  • New Features

    • Web SDK operations can now be invoked using both callable and property-based syntax.
    • Native function helpers, such as .call, are supported when invoking SDK operations.
    • Initialization now preserves existing operation properties while continuing to queue unrecognized calls.
  • Bug Fixes

    • Improved compatibility with transpiled optional-call patterns and initialization behavior.

@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 5cd70cb1-baea-4c7d-98dd-a7945a0d1f23

📥 Commits

Reviewing files that changed from the base of the PR and between 3060ca1 and 726fdf8.

📒 Files selected for processing (5)
  • packages/sdks/web/src/callable.test.ts
  • packages/sdks/web/src/callable.ts
  • packages/sdks/web/src/init-snippet.ts
  • packages/sdks/web/src/tracker.ts
  • packages/sdks/web/vitest.config.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The SDK adds a reusable callable wrapper for window.op, updates initialization property forwarding, replaces the tracker’s inline proxy, and adds Vitest coverage for callable and queued invocation behavior.

Changes

Callable Open Panel

Layer / File(s) Summary
Callable wrapper and validation
packages/sdks/web/src/callable.ts, packages/sdks/web/src/callable.test.ts, packages/sdks/web/vitest.config.ts
Adds createCallableOpenPanel, which supports direct calls, property calls, bound methods, and Function.prototype.call. Tests cover these invocation forms.
Initialization property forwarding
packages/sdks/web/src/init-snippet.ts, packages/sdks/web/src/callable.test.ts
Existing properties now use Reflect.get in both runtime and generated initialization proxies. Unknown properties still queue calls, and q still exposes the queue.
Tracker integration
packages/sdks/web/src/tracker.ts
Replaces the tracker’s inline proxy with createCallableOpenPanel(op).

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 726fd

The SDK’s callable API behavior is covered for direct, property, and transpiled Function-helper invocation paths, with no actionable merge-blocking issue identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preserving native function properties on the callable web SDK proxy.
Linked Issues check ✅ Passed The changes satisfy the coding requirements in issue #240. createCallableOpenPanel falls back to the callable target for native properties such as .call, .apply, and .bind. The pre-load snippe…
Out of Scope Changes check ✅ Passed The changes stay within issue #240. The callable helper, tracker integration, initialization-snippet update, regression tests, and Vitest configuration all support the Proxy behavior or its verificati…
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@CLAassistant

CLAassistant commented Sep 15, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

BUG: _window_op.call is not a function

2 participants