Skip to content

Conversation

@zhiyuanliang-ms
Copy link
Member

@zhiyuanliang-ms zhiyuanliang-ms commented Oct 2, 2025

Snapshot Reference

A snapshot reference is a configuration setting that references a snapshot in the same App Configuration store. When loaded, the provider resolves it and adds all key-values from that snapshot. Using snapshot references enables switching between snapshots at runtime, unlike using a snapshot selector, which requires code changes and/or restarts to switch to a new snapshot.

The content type of a snapshot reference is: "application/json; profile=\"https://azconfig.io/mime-profiles/snapshot-ref\"; charset=utf-8";

Behavior difference from .NET provider

Different from PR #689

The snapshot api design in JS provider is different from .NET provider.
In JS provider, keyvalue and feature flag are fully decoupled. The load and refresh operations for key values and feature flags are performed separatedly. The selector for key value will not load feature flags, vice versa. You must explicitly specify selectors for them.

To load key value or feature flag from snapshot, you must use a snapshot selector i.e. SettingSelector.snapshotName. When you specify a snapshot selector for key values, even if there is any feature flag in that snapshot, the feature flag will not be loaded when loading key values. You must also specify the same snapshot selector in FeatureFlagOptions.

It is a library level choice. We won't break it. So, when resolving a snapshot reference, feature flags in the snapshot will be ignored.

Note: This PR is not ready for review yet. It depends on the Azure JS SDK adding support for snapshot reference types. After that update, I’ll replace all existing helper functions with the SDK ones.

@zhiyuanliang-ms
Copy link
Member Author

Should we handle the case that sentinel key is a snapshot reference?

@zhiyuanliang-ms zhiyuanliang-ms changed the base branch from main to preview November 13, 2025 15:16
@zhiyuanliang-ms zhiyuanliang-ms force-pushed the zhiyuanliang/snapshot-reference branch from 1785813 to 90d0727 Compare November 13, 2025 15:24
@zhiyuanliang-ms zhiyuanliang-ms changed the base branch from preview to main November 13, 2025 15:24
@zhiyuanliang-ms zhiyuanliang-ms marked this pull request as ready for review November 13, 2025 15:25
const snapshotRef: ConfigurationSetting<SnapshotReferenceValue> = parseSnapshotReference(setting);
const snapshotName = snapshotRef.value.snapshotName;
if (!snapshotName) {
throw new SnapshotReferenceError(`Invalid format for Snapshot reference setting '${setting.key}'.`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use InvalidOperationError if a snapshot has the wrong composition type. Can't we use it for this case as well?

Copy link
Member Author

@zhiyuanliang-ms zhiyuanliang-ms Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about throwing SnapshotReferenceError when composition type is wrong. This will make it consistent with how we throw KeyValueReferenceError

BTW, InvalidOperationError is not a javascript built-in error type. It is a custom error type defined by us.

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.

3 participants