optimizely/javascript-sdk

[BUG] BatchEventProcessor stops sending for B/f Cache loads

Closed this issue · 6 comments

Is there an existing issue for this?

  • I have searched the existing issues

SDK Version

6.1.0

Current Behavior

When having pages restored from B/f Cache, the BatchEventProcessor stops sending events to the endpoints. This causes a gap in data.

Expected Behavior

Events should continue being send.

Steps To Reproduce

  1. Create an application with a simple setup as described in Optimizely Docs
  2. Send events permanently and monitor the events endpoint
  3. Use Chromes Application > Back/forward cache > Test b/f cache button to simulate page restore
  4. Verify that events are not send anymore

Link to video demonstrating the issue

SDK Type

Browser

Node Version

24.9.0

Browsers impacted

At least Chrome

Link

import './style.css';
import { createInstance, createPollingProjectConfigManager, createBatchEventProcessor } from '@optimizely/optimizely-sdk';

const testingClient = createInstance({
  projectConfigManager: createPollingProjectConfigManager({
    sdkKey: {SDK_KEY},
    updateInterval: 20000,
    autoUpdate: true
  }),
  eventProcessor: createBatchEventProcessor({
    batchSize: 1,
    flushInterval: 1000
  }),
});

testingClient.onReady().then(() => {
  setInterval(() => {
    testingClient.track('search_dom_interactive_ms', '123');
  }, 3000);
});

Code

Running flag

Mismatch

Logs

No response

Severity

No response

Workaround/Solution

Very suboptimal hack to set the state to running (using private properties and is super error prone). Also it seems that this solution does not work in all cases because numbers are still lower than without B/f cache enabled.

window.addEventListener('pageshow', (event) => {
  if (event.persisted) {
    client.eventProcessor.state = 2;
  }
});

Recent Change

No response

Conflicts

No response

Hi @fooku18 , thank you for reporting the issue.

To flush all the pending events, we close the client instance on page hide/unload here. I suspect this is what is causing the issue. We'll start working on a fix ASAP.

We have internal ticket FSSDK-11879 scheduled for current sprint.

@raju-opti do you have any ETA when this will be released?

Hello @fooku18 , we have a release planned later this week.

Hi @fooku18 , this should be fixed in v6.2.0. Could you please check?

@raju-opti
I have successfully tested it in my dev setup 👍