Skip to content

Replace AnyCodable with JSONSerialization in IAFNativeBridgeEvent#536

Draft
ab1470 wants to merge 1 commit intofeat/flyouts-formsfrom
ab/flyouts-forms-suggestions
Draft

Replace AnyCodable with JSONSerialization in IAFNativeBridgeEvent#536
ab1470 wants to merge 1 commit intofeat/flyouts-formsfrom
ab/flyouts-forms-suggestions

Conversation

@ab1470
Copy link
Copy Markdown
Contributor

@ab1470 ab1470 commented Apr 2, 2026

Summary

  • Replace AnyCodable decode-then-re-encode pattern with typed Codable payload structs (FormWillAppearPayload, TrackProfileEventPayload, TrackAggregateEventPayload)
  • Decode once into the right type — no opaque Data passthrough, no re-parsing downstream
  • Removes import AnyCodable from both source and test files
  • Consumers access typed fields directly (e.g. payload.metric, payload.formId) instead of deserializing Data blobs

Test plan

  • All 9 existing IAFNativeBridgeEventTests pass
  • Full package build succeeds

🤖 Generated with Claude Code

@ab1470 ab1470 force-pushed the ab/flyouts-forms-suggestions branch from 07ce4ae to bc5abd4 Compare April 2, 2026 20:32
Decode formWillAppear, trackProfileEvent, and trackAggregateEvent into
typed Codable structs instead of round-tripping through AnyCodable to
opaque Data. This gives compile-time safety, eliminates the external
dependency from this file, and simplifies downstream consumers.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ab1470 ab1470 force-pushed the ab/flyouts-forms-suggestions branch from bc5abd4 to d439c23 Compare April 2, 2026 22:10
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

formLifecycleContinuation.yield(.dismiss)
case let .trackProfileEvent(data):
if let jsonEventData = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
let metricName = jsonEventData["metric"] as? String {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Aggregate event re-encoding silently drops unknown JSON fields

Medium Severity

The trackAggregateEvent path still performs a decode-then-re-encode round-trip (decoding to TrackAggregateEventPayload, then encoding back to Data via JSONEncoder), but now uses a typed struct instead of AnyCodable. Any JSON fields sent by JavaScript that aren't explicitly modeled in the struct (e.g., future server-side additions) are silently dropped during decoding, causing incomplete aggregate event data to reach the backend. The previous AnyCodable approach preserved all fields.

Additional Locations (1)
Fix in Cursor Fix in Web

@belleklaviyo belleklaviyo mentioned this pull request Apr 3, 2026
9 tasks
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.

1 participant