Releases: happykit/flags
v2.0.3
v2.0.2
v2.0.1
v2.0.0
- adds support for Next.js Middleware
- you can now use
getEdgeFlags
to load your flags in middleware - see a demo of using flags in middleware at flags.happykit.dev/demo/middleware
- you can now use
BREAKING CHANGES
next
v12.0.2 is now the new minimalpeerDependency
(as this is the first version supporting middleware and settingmaxAge
correctly)- older Next.js versions should still if you are not using
getEdgeFlags
- older Next.js versions should still if you are not using
- we now recommend storing your config in
flags.config.js
as shown in the example and then importingflags.config
into_app
- note that
configure()
is now called from withinflags.config.ts
- note that
configure()
is no longer called in_app.tsx
- calling
configure()
fromflags.config.ts
prepares you for loading flags in_middleware
by importingflags.config
- note that
v1.1.0
This release adds the ability to specify a timeout for loading flags on the server. Flags usually resolve within ~75ms, but in case something goes wrong the flag evaluation requests can now be aborted at a user-configured timeout.
The configuration option can be set globally in configure()
for clientLoadingTimeout
, serverLoadingTimeout
and staticLoadingTimeout
each.
The global configuration can be overwritten per page by useFlags
and getFlags
by specifying the loadingTimeout
option.
Adds
config.clientLoadingTimeout
: The timeout used byuseFlags
on the clientconfig.serverLoadingTimeout
: The timeout used bygetFlags
inside ofgetServerSideProps
(for server-side rendering)config.staticLoadingTimeout
: The timeout used bygetFlags
inside ofgetStaticProps
orgetStaticPaths
(for static site generation)
Deprecates
configure({ loadingTimeout })
. Useconfigure({ clientLoadingTimeout })
instead. It behaves the same, it was renamed only.
Full Changelog: v1.0.2...v1.1.0
v1.0.2
v1.0.1
v1.0.0
A complete rewrite of the @happykit/flags
client
The main new features are that it supports
- rollouts
user
andtraits
- instead of storing only the last request thing in
localStorage
it now uses a runtime cache for all requests - acts in a
stale-while-revalidate
fashion, inspired byswr
- full support for any rendering scenario (client-side, server-side or static site generation)
- the client now supports a
loadingTimeout
after which it will fall back to the default flags
Technically this repo now contains an example which is deployed to flags.happykit.dev and we've switched to preconstruct.tools as the bundler.
Breaking changes
instead of a single entry point, the package now has multiple entry points
@happykit/flags/config
: Configuration functions@happykit/flags/server
: Everything related to the server@happykit/flags/client
: Everything related to the client@happykit/flags/context
: A helper to pass theflagBag
down through React's context
useFlags()
returns an object instead of the flags
flags
are now benull
while the flags are loading
// before
import { useFlags } from "@happykit/flags"
const flags = useFlags()
// after
import { useFlags } from "@happykit/flags/client"
const { flags } = useFlags()
The object returned from useFlags()
is sometimes referred to as the flagBag
. It has the following properties now:
const flagBag = useFlags()
flagBag.flags; // the feature flags or null, optimistically resolved from the cache
flagBag.data; // the feature flags as loaded from the server; does not use cache; does not use fallbacks
flagBag.error; // null or a a string; contains the reason the flags could not be loaded if "data" is null
flagBag.fetching; // boolean; true when the flags are currently being refetched
flagBag.settled; // boolean; true when the flags are not expected to change again (unless your input or flag definition changes)
flagBag.revalidate; // function which revalidates the flags for the given user and traits
See here for more information.
getFlags
now returns an object instead of the flags
// before
import { useFlags, getFlags } from '@happykit/flags';
export default function FooPage(props) {
const flags = useFlags({ initialFlags: props.initialFlags });
return flags.xzibit ? 'Yo dawg' : 'Hello';
}
export const getServerSideProps = async () => {
const initialFlags = await getFlags();
return { props: { initialFlags } };
};
// after
import { useFlags } from "@happykit/flags/client";
import { getFlags } from "@happykit/flags/server";
export const getServerSideProps = async (context) => {
const { initialFlagState } = await getFlags({ context });
return { props: { initialFlagState } };
};
export default function FooPage(props) {
const { flags } = useFlags({ initialState: props.initialFlagState });
return flags?.xzibit ? 'Yo dawg' : 'Hello';
}
See here for more information.
configure
configure
now takes anenvKey
instead of aclientId
// before
import { configure } from '@happykit/flags';
configure({ clientId: process.env.NEXT_PUBLIC_FLAGS_CLIENT_ID });
// after
import { configure } from "@happykit/flags/config";
configure({ envKey: process.env.NEXT_PUBLIC_FLAGS_ENVIRONMENT_KEY });
See here for more information.