Skip to content

Commit

Permalink
refactor: change http-adapter to eager mode (#3548)
Browse files Browse the repository at this point in the history
* refactor: change http-adapter to eager mode

* Create cold-lemons-whisper.md

* fix: ts-ignore comment position
  • Loading branch information
tdeekens authored Jun 10, 2024
1 parent 4fa5f44 commit 222dd0c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-lemons-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@commercetools-frontend/application-shell": patch
---

Change `flopflip`'s `http-adapter` cache mode to be eager.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import combineAdapters from '@flopflip/combine-adapters';
import httpAdapter from '@flopflip/http-adapter';
import ldAdapter from '@flopflip/launchdarkly-adapter';
import { ConfigureFlopFlip } from '@flopflip/react-broadcast';
import { cacheIdentifiers, cacheModes } from '@flopflip/types';
import {
type TAdapterIdentifiers,
cacheIdentifiers,
cacheModes,
adapterIdentifiers,
} from '@flopflip/types';
import type { TFlags } from '@flopflip/types';
import { useApplicationContext } from '@commercetools-frontend/application-shell-connectors';
import {
Expand Down Expand Up @@ -93,13 +98,17 @@ const parseFlags = (fetchedFlags: TFetchedFlags): TParsedHttpAdapterFlags =>
])
);

const getCacheMode = () => {
// @ts-ignore
if (typeof window.Cypress !== 'undefined') {
const getCacheMode = (adapterIdentifier: TAdapterIdentifiers) => {
if (
// @ts-ignore
typeof window.Cypress !== 'undefined' ||
adapterIdentifier === adapterIdentifiers.http
) {
// Temporary workaround: when running in Cypress, do not use lazy mode
// as the flag is not being updated in time during the test run.
return cacheModes.eager;
}

return cacheModes.lazy;
};

Expand Down Expand Up @@ -146,7 +155,7 @@ export const SetupFlopFlipProvider = (props: TSetupFlopFlipProviderProps) => {
},
launchdarkly: {
cacheIdentifier: cacheIdentifiers.local,
cacheMode: getCacheMode(),
cacheMode: getCacheMode(adapterIdentifiers.launchdarkly),
sdk: {
// Allow to overwrite the client ID, passed via the `additionalEnv` properties
// of the application config.
Expand All @@ -166,7 +175,7 @@ export const SetupFlopFlipProvider = (props: TSetupFlopFlipProviderProps) => {
// polling interval set to 15 minutes
pollingIntervalMs: 1000 * 60 * 15,
cacheIdentifier: cacheIdentifiers.local,
cacheMode: getCacheMode(),
cacheMode: getCacheMode(adapterIdentifiers.http),
user: {
key: props.user?.id,
},
Expand Down

0 comments on commit 222dd0c

Please sign in to comment.