Repository navigation
[FSSDK-13343] Skip the default browser event store when localStorage is unavailable - #1184
Raju Ahmed (raju-opti) wants to merge 1 commit into
Conversation
…is unavailable The browser batch event processor now checks whether localStorage can be accessed before creating its default LocalStorageCache-backed EventStore. If it can't (SSR, storage blocked by browser settings or a sandboxed iframe), the processor runs without an event store and logs a startup warning. A user-provided eventStore is used as before. getBatchEventProcessor accepts startupLogs from platform factories and prepends them to its own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
The focused fallback preserves existing optional-store behavior, regression tests cover the changes, and no blocking issues were identified.
No open issues 🎉
What changed in this PR
This PR addresses #1182 by skipping the browser’s default persistent event store when localStorage is inaccessible, while preserving event batching, dispatch, and custom event stores.
Changes:
- Adds a guarded
localStorageavailability check and a startup warning when persistence is disabled. - Allows platform factories to supply startup logs without mutating the caller’s array.
- Adds regression tests for storage availability, custom stores, and startup-log propagation.
| File | Description |
|---|---|
| lib/utils/env/browser.ts | Adds the guarded storage availability check. |
| lib/utils/env/browser.spec.ts | Tests accessible, null, missing, and blocked storage. |
| lib/message/error_message.ts | Defines the persistence-disabled warning. |
| lib/event_processor/event_processor_factory.ts | Copies supplied startup logs before adding processor logs. |
| lib/event_processor/event_processor_factory.spec.ts | Tests log propagation and input-array preservation. |
| lib/event_processor/event_processor_factory.browser.ts | Conditionally creates the default store and supplies the warning. |
| lib/event_processor/event_processor_factory.browser.spec.ts | Tests fallback behavior and custom-store preservation. |
Review effort: Balanced
Md Junaed Hossain (junaed-optimizely)
left a comment
There was a problem hiding this comment.
Looks good overall. Should we add a catch in lib/event_processor/batch_event_processor.ts:275 ? The localStorage check covers the default store, but a user-provided eventStore that rejects would still cause the unhandled rejection!
In that case, I would say the responsibility to ensure that the store that is passed in works is on the user. |
Summary
isLocalStorageAvailable()inlib/utils/env/browser.ts. It returnsfalsewhen reading thelocalStorageglobal throws (aReferenceErrorwhere it isn't defined, such as SSR, or aSecurityErrorwhere storage is blocked, such as disabled cookies or sandboxed iframes) or when the global isnull.createBatchEventProcessoronly builds its defaultLocalStorageCache-backedEventStorewhen localStorage is available. Otherwise it runs without an event store and adds a Warn startup log:localStorage is not available, events will not be persisted.A user-providedeventStoreis used exactly as before, whether or not localStorage is available.getBatchEventProcessoraccepts astartupLogsoption and puts those logs before its own, without changing the caller's array. The option is on the internalBatchEventProcessorFactoryOptionsonly; the publicBatchEventProcessorOptionsis unchanged.Before this change, the browser factory always created a
LocalStorageCacheevent store. Where localStorage can't be accessed, every store operation threw. With no event store, events are still batched and dispatched; failed events just aren't persisted for retry across page loads.Test plan
lib/utils/env/browser.spec.ts:localStoragethat is accessible,null, not defined (ReferenceError), and blocked (SecurityError).event_processor_factory.browser.spec.ts: no event store and a startup warning when localStorage is unavailable; no warning when it is available; a providedeventStoreis wrapped withgetPrefixEventStorewhether or not localStorage is available, with no warning.event_processor_factory.spec.ts: providedstartupLogsare included with the processor's own, and the input array isn't changed.tsc --noEmit,eslinton the changed files andvalidate-platform-isolation.Issues
🤖 Generated with Claude Code