Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: change http-adapter to eager mode #3548

Merged
merged 3 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading