Skip to content

Sveltekit flags enhancements#75

Merged
dferber90 merged 25 commits intomainfrom
sveltekit-flags-enhancements
Mar 21, 2025
Merged

Sveltekit flags enhancements#75
dferber90 merged 25 commits intomainfrom
sveltekit-flags-enhancements

Conversation

@dummdidumm
Copy link
Copy Markdown
Contributor

@dummdidumm dummdidumm commented Feb 23, 2025

This enhances the SvelteKit adapter in several ways:

  • use $env/dynamic/private, which means people don't have to pass FLAGS_SECRET manually anymore. This means Vite will have to compile this in the context of the app, but that's not a problem and should happen automatically
  • allow a created flag to be called oustide of the lifecycle of the handle hook, with a request object being the key for deduplication etc. This allows it to be called from e.g. edge middleware
  • add support for identifiers, including deduplicating their calls. This is achieved by adding a Map onto the context in which flags run, with the identify function being the key. That means calls are deduplicated automatically as soon as you share a stable reference to the function across flags
  • add createPrecomputedFlags which is a function for generating permutations, then precomputing one and retrieving it. It's different to the Next.js API because it does not need you to pass the array of flags everywhere, instead you define which flags belong to which route param once and then access methods on the returned object. Using it feels a bit nicer than the Next.js approach IMO, but open to suggestions model precompute API closely after Next.js to align

This needs sveltejs/kit#13477 to land first, so that you can actually precompute something in middleware, and it would be good to also enhance the example SvelteKit app as well then. Makes use of the new async reroute feature in SvelteKit.

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Feb 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
flags-sdk-snippets ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2025 11:22am
flags-sdk-sveltekit-snippets ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2025 11:22am
shirt-shop ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2025 11:22am
summer-sale ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2025 11:22am

@dummdidumm
Copy link
Copy Markdown
Contributor Author

Ready for review - let me know if the examples need tweaking / should be aligned in specific ways with the Next examples.

Also, is there anything with regards to the docs we should be updating / adjusting at the same time?

@dferber90 dferber90 merged commit 701f3c2 into main Mar 21, 2025
13 checks passed
@dferber90 dferber90 deleted the sveltekit-flags-enhancements branch March 21, 2025 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants