Repository navigation
fix(react-native-plugin): build without posthog-ios's Surveys trait - #5564
Conversation
The full SwiftPM path leaves out posthog-ios's Surveys trait (#5237), which removes PostHogConfig.surveys, so `config.surveys = false` didn't compile there. Package.swift now defines POSTHOG_IOS_NO_SURVEYS for the plugin target and the line is skipped under it. The CocoaPods path still sets it: React Native's spm_dependency can't pass traits, so it builds posthog-ios with surveys on by default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
📝 No Changeset FoundThis PR doesn't include a changeset. A changeset is required to release a new version. How to add a changesetRun this command and follow the prompts: pnpm changesetRemember: Never use |
|
There was a problem hiding this comment.
PostHog Review · Standard · reviewed f4fb0ff: 1 Should fix.
See this review and its findings in PostHog Review. Comment @posthog review --deep for a Deep review. A Deep review takes longer and looks deeper than a Standard review.
| #if !POSTHOG_IOS_NO_SURVEYS | ||
| config.surveys = false | ||
| #endif |
There was a problem hiding this comment.
P2 · Preserve the survey opt-out when SwiftPM unifies traits
When a full-SPM app also depends on posthog-ios with default traits, SwiftPM unions the trait requests and compiles Surveys. POSTHOG_IOS_NO_SURVEYS still skips config.surveys = false, so PostHogConfig retains its true default and installs native survey UI alongside JS surveys. Preserve the opt-out when dependency trait unification enables surveys.
Coherence📄 0 spec file errors · ⛔ 0 broken rules · 🚪 2 unchecked inputs · 🐛 0 bugs that came back What is Coherence?Coherence compares the code with its spec files ( This check read 44 parts of the code and 7 rules. Note These findings do not make this check fail. None of these findings are in files that this pull request changes. You do not need to fix them in this pull request. 🚪 Unchecked inputs (2)
What this means and how to fix itInput from outside this code comes in at these places. The spec does not say what checks that input. 10 more places were already like this when Coherence was added. This list does not show them. To close one of these, find the place by its name in the
To get the line to add, run |
SDK performance: posthog-nodeBenchmarks completed. No changes flagged for review. Flags require at least a 5% change in the median and all six pairs agreeing on direction. This is a noise filter, not proof of a performance change or a CI gate. View all results
Values are medians of paired measurements. Not flagged does not mean unchanged. Unavailable means a measurement could not be provided, not zero. Estimated allocation measurements retain their instrumentation uncertainty. RSS measures the whole process, not just SDK allocations; observed peaks are sampled checkpoints. Paired ranges in the diagnostics describe variability, not confidence intervals. Each shard uses its own runner; compare Before PR against With PR within a row, not across shards. Compared 102 metric rows; 102 rows shown in all results. Omitted or shortened data remain in |
Problem
#5237 turned off posthog-ios's
Surveystrait in the plugin'sPackage.swift, but the plugin still setsconfig.surveys = false. Without the trait, posthog-ios 4.0 has noPostHogConfig.surveys, so apps on React Native's full Swift Package Manager integration fail to compile the plugin. #5237's full-SPM CI job couldn't show this: it fails earlier because posthog-ios 4.0.0 isn't published yet.The line can't just be deleted. The CocoaPods path resolves posthog-ios through React Native's
spm_dependency, which can't pass traits, so it builds posthog-ios with every default trait, surveys included, andsurveysdefaults totrue. Without the line, those apps would show native surveys on top of the JS ones.Changes
ios/Package.swift: thePosthogReactNativePlugintarget definesPOSTHOG_IOS_NO_SURVEYS. That target compiles onlyPosthogReactNativePlugin.swift, so the define reaches the file.ios/PosthogReactNativePlugin.swift:config.surveys = falseis wrapped in#if !POSTHOG_IOS_NO_SURVEYS.config.surveys = falsespm_dependency)Surveystrait)Remove the guard, the define and the line once every install path can leave the trait out: when
spm_dependencycan pass traits, or when the podspec path goes away.No changeset: the 3.0 changeset already says full-SPM apps no longer bundle native surveys, which stays true.
Release info Sub-libraries affected
Libraries affected
Checklist
How it was tested
Three scratch Swift packages depending on posthog-ios 4.0 (
fix/v4-capture-setup-generation, the head of the 4.0 stack), each compiling the plugin's exact#ifblock, built for the iOS simulator withxcodebuild:["SessionReplay", "CrashReporting"]with the define (the full-SPM path): builds.["SessionReplay", "CrashReporting"]without the define (the code before this PR): fails withvalue of type 'PostHogConfig' has no member 'surveys'.Not run: a React Native app build on either path, since posthog-ios 4.0.0 isn't tagged yet.
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Made with Claude Code during the posthog-ios 4.0 pre-release review. Options considered: keep the
Surveystrait on and the line as is (simplest, but full-SPM apps bundle unused survey code), or a runtimeresponds(to:)/KVC check (no build setting, but a rename in posthog-ios would silently break it). A define set only byPackage.swiftkeeps native surveys out of full-SPM apps and still turns them off on the CocoaPods path.🤖 Generated with Claude Code