Bot releases are hidden (Show)
Published by dferber90 about 2 years ago
1822587: BREAKING CHANGE: Configuration overhaul
This release changes HappyKit's configuration approach.
Previously you had to create a flags.config.js
file and import it into your pages/_app.js
and into every middleware that wanted to use feature flags. If you were using your own AppFlags
type, you also had to pass this type every time you invoked getFlags()
, useFlags()
or getEdgeFlags()
. And the configuration options for client-, server- and edge were mixed together into a single flags.config.js
file.
This release replaces the existing configuration approach with a new one. This new approach configuration prepares happykit for upcoming features.
flags
folderFollow the updated Setup instructions to create the flags
folder in your own application, and fill it with.
After this step, you should have
./flags/config.ts
which exports a configuration./flags/client.ts
which exports a useFlags
function./flags/server.ts
which exports a getFlags
function./flags/edge.ts
which exports a getEdgeFlags
functionEnable Absolute Imports as described here.
Then change the application code in your pages/
folder to use these functions from your flags/
folder instead of from @happykit/flags
:
- import { useFlags } from "@happykit/flags/client"
+ import { useFlags } from "flags/client"
- import { getFlags } from "@happykit/flags/server"
+ import { getFlags } from "flags/server"
- import { getEdgeFlags } from "@happykit/flags/edge"
+ import { getEdgeFlags } from "flags/edge"
_Note that because of the absolute imports we configured in step 2, all imports from "flags/"
will use the local flags folder you created in step 1.*
We can now delete the old setup since we no longer need it
flags.config.js
flags.config
import from your pages/_app
file
pages/_app
file if it's not doing anything else anymoreflags.config
from your middlewarePublished by dferber90 about 2 years ago
Adds support for node v18
AbortController
polyfill. The AbortController
is now only used if it exists as a global in the surrounding environmentPublished by dferber90 over 2 years ago
getConfig()
to fix it #24Breaking change
If you were doing import { config } from "@happykit/flags/config"
, you now need to import { getConfig } from "@happykit/flags/config"
. I believe most people are not importing config
into their app.
This was a breaking I only realized after publishing as v2.0.6, so the sem ver does not reflect the breaking change. I apologize if this broke your build.
Published by dferber90 over 2 years ago
This is a special once-off release which is equal to v2.0.5
, except for additional latency metrics reporting.
Published by dferber90 over 2 years ago
Published by dferber90 over 2 years ago
Published by dferber90 over 2 years ago
nanoid
dependency to v3.2.0 to resolve a dependabot warning dc9728b65ad55590398537ce57cb2713cdc80db2Published by dferber90 almost 3 years ago
Published by dferber90 almost 3 years ago
static
field from generated requestBody
, https://github.com/happykit/flags/pull/19
Published by dferber90 almost 3 years ago
getEdgeFlags
to load your flags in middlewareBREAKING CHANGES
next
v12.0.2 is now the new minimal peerDependency
(as this is the first version supporting middleware and setting maxAge
correctly)
getEdgeFlags
flags.config.js
as shown in the example and then importing flags.config
into _app
configure()
is now called from within flags.config.ts
configure()
is no longer called in _app.tsx
configure()
from flags.config.ts
prepares you for loading flags in _middleware
by importing flags.config
Published by dferber90 about 3 years ago
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.
config.clientLoadingTimeout
: The timeout used by useFlags
on the clientconfig.serverLoadingTimeout
: The timeout used by getFlags
inside of getServerSideProps
(for server-side rendering)config.staticLoadingTimeout
: The timeout used by getFlags
inside of getStaticProps
or getStaticPaths
(for static site generation)configure({ loadingTimeout })
. Use configure({ clientLoadingTimeout })
instead. It behaves the same, it was renamed only.Full Changelog: https://github.com/happykit/flags/compare/v1.0.2...v1.1.0
Published by dferber90 about 3 years ago
GetStaticPathsContext
as context
in getFlags({ context })
Published by dferber90 over 3 years ago
FlagBag
type to @happykit/flags/client
Published by dferber90 over 3 years ago
A complete rewrite of the @happykit/flags
client
The main new features are that it supports
user
and traits
localStorage
it now uses a runtime cache for all requestsstale-while-revalidate
fashion, inspired by swr
loadingTimeout
after which it will fall back to the default flagsTechnically this repo now contains an example which is deployed to flags.happykit.dev and we've switched to preconstruct.tools as the bundler.
@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 the flagBag
down through React's contextuseFlags()
returns an object instead of the flagsflags
are now be null
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 an envKey
instead of a clientId
// 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.
Published by dferber90 about 4 years ago
localStorage
#1disableCaching
option #1Published by dferber90 about 4 years ago
Flags
typeusePrimitiveFlags
export