Skip to content

SDK-92 Fix intermittent in-app message positioning#1001

Merged
sumeruchat merged 6 commits intomasterfrom
feature/SDK-92-fix-iam-position-intermittent
Mar 24, 2026
Merged

SDK-92 Fix intermittent in-app message positioning#1001
sumeruchat merged 6 commits intomasterfrom
feature/SDK-92-fix-iam-position-intermittent

Conversation

@sumeruchat
Copy link
Copy Markdown
Contributor

@sumeruchat sumeruchat commented Jan 30, 2026

What

Fixes intermittent positioning issues where in-app messages configured for bottom/top/center positions display in the wrong location.

Jira ticket: SDK-92

Root Cause

viewDidLayoutSubviews() calls resizeWebView() before the webview content finishes loading. When document.body.offsetHeight is evaluated via JavaScript before the DOM is ready, it returns 0 or incorrect values, causing position calculations to fail.

The lifecycle was:

  1. viewDidLoad() loads HTML into webview
  2. viewDidLayoutSubviews() called (before content ready) → calculates wrong position
  3. webView(_:didFinish:) called (after content ready) → recalculates, but may be too late

Solution

Added webViewDidFinishLoading flag that prevents resizeWebView() from executing in viewDidLayoutSubviews() until the webview finishes loading. This ensures position is only calculated when document.body.offsetHeight returns accurate values.

Changes

  • IterableHtmlMessageViewController.swift

    • Added webViewDidFinishLoading flag (initially false)
    • Set flag to true in webView(_:didFinish:)
    • Guard viewDidLayoutSubviews() resize logic with flag check
  • IterableHtmlMessageViewControllerTests.swift

    • Added testWebViewFinishLoadingFlagBehavior() to verify flag lifecycle

Impact

  • Breaking changes: None
  • Dependencies: None
  • Performance: No impact (just defers position calculation until content is ready)

Testing

Unit tests: New test verifies the webViewDidFinishLoading flag behavior

Manual testing:

  1. Create a bottom position in-app message
  2. Trigger it multiple times quickly
  3. Verify it always displays at the bottom (not intermittently in center/top)
  4. Repeat for top and center positions

SDK-92: In-app messages were intermittently displaying in the wrong position (e.g., bottom position messages appearing in center/top).

Root cause: viewDidLayoutSubviews calls resizeWebView before the webview content finishes loading. When document.body.offsetHeight is evaluated before the DOM is ready, it returns 0 or incorrect values, causing wrong position calculations.

Fix: Added webViewDidFinishLoading flag that prevents resizeWebView from executing in viewDidLayoutSubviews until after the webview finishes loading. This ensures position is only calculated when document.body.offsetHeight returns the correct value.

Changes:
- Added webViewDidFinishLoading flag (initially false)
- Set flag to true in webView(_:didFinish:)
- Guard viewDidLayoutSubviews resize logic with flag check
- Added test to verify flag behavior
@joaodordio joaodordio force-pushed the feature/SDK-92-fix-iam-position-intermittent branch from 9df77c5 to c9302a7 Compare February 18, 2026 15:27
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.79%. Comparing base (8cf5fd0) to head (98c46d5).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1001      +/-   ##
==========================================
+ Coverage   70.75%   70.79%   +0.04%     
==========================================
  Files         112      112              
  Lines        9191     9197       +6     
==========================================
+ Hits         6503     6511       +8     
+ Misses       2688     2686       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sumeruchat sumeruchat merged commit df82407 into master Mar 24, 2026
15 of 16 checks passed
@sumeruchat sumeruchat deleted the feature/SDK-92-fix-iam-position-intermittent branch March 24, 2026 16:51
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.

3 participants