Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat: negate feature flags in $Show (#38871)

Charis3fe03d07ab44
diff --git a/apps/docs/content/guides/getting-started.mdx b/apps/docs/content/guides/getting-started.mdx
index c41613e11db..b95027ac134 100644
--- a/apps/docs/content/guides/getting-started.mdx
+++ b/apps/docs/content/guides/getting-started.mdx
@@ -93,6 +93,8 @@ hideToc: true
### Framework quickstarts
+<$Show if="docs:framework_quickstarts">
+
<div className="grid lg:grid-cols-12 gap-6 not-prose">
{[
{
@@ -211,6 +213,14 @@ hideToc: true
})}
</div>
+</$Show>
+
+<$Show if="!quickstarts:hide_nimbus">
+
+<$Partial path="quickstart_nimbus.mdx" />
+
+</$Show>
+
<$Show if="docs:web_apps">
### Web app demos
diff --git a/apps/docs/features/directives/Show.test.ts b/apps/docs/features/directives/Show.test.ts
index cbe3024a114..3fea57f5012 100644
--- a/apps/docs/features/directives/Show.test.ts
+++ b/apps/docs/features/directives/Show.test.ts
@@ -59,18 +59,51 @@ Content after the show block.
expect(isFeatureEnabled).toHaveBeenCalledWith('test-feature')
})
- it('should remove entire $Show block and children when feature is disabled', async () => {
+ it('should keep children when negated feature is disabled', async () => {
vi.mocked(isFeatureEnabled).mockReturnValue(false)
const markdown = `
# Test content
-<$Show if="disabled-feature">
-This content should NOT be visible when feature is disabled.
+<$Show if="!negated-feature">
+This content should be visible when the feature is disabled.
+
+## Additional content
+
+More text that should remain.
+</$Show>
+
+Content after the show block.
+`.trim()
+
+ const mdast = fromDocsMarkdown(markdown)
+ const transformed = showRemark()(mdast)
+ const output = toMarkdown(transformed, { extensions: [mdxToMarkdown()] })
+
+ const expected = `
+# Test content
-## This heading should also be removed
+This content should be visible when the feature is disabled.
-Some more content that should be hidden.
+## Additional content
+
+More text that should remain.
+
+Content after the show block.
+`.trimStart()
+
+ expect(output).toEqual(expected)
+ expect(isFeatureEnabled).toHaveBeenCalledWith('negated-feature')
+ })
+
+ it('should remove $Show block when negated feature is enabled', async () => {
+ vi.mocked(isFeatureEnabled).mockReturnValue(true)
+
+ const markdown = `
+# Test content
+
+<$Show if="!enabled-negated-feature">
+This content should NOT be visible because the feature is enabled.
</$Show>
Content after the show block should remain.
@@ -87,7 +120,7 @@ Content after the show block should remain.
`.trimStart()
expect(output).toEqual(expected)
- expect(isFeatureEnabled).toHaveBeenCalledWith('disabled-feature')
+ expect(isFeatureEnabled).toHaveBeenCalledWith('enabled-negated-feature')
})
it('should handle multiple $Show blocks with different feature flags', async () => {
diff --git a/apps/docs/features/directives/Show.ts b/apps/docs/features/directives/Show.ts
index 94401222466..5a1e0b32e43 100644
--- a/apps/docs/features/directives/Show.ts
+++ b/apps/docs/features/directives/Show.ts
@@ -38,13 +38,24 @@ export function showRemark() {
if (node.name !== '$Show') return
const parent = ancestors[ancestors.length - 1]
- const featureName = getAttributeValue(node, 'if')
+ const rawFeatureName = getAttributeValue(node, 'if')
- if (typeof featureName !== 'string') {
+ if (typeof rawFeatureName !== 'string') {
throw new Error('$Show directive requires a string value for the "if" attribute')
}
- const shouldShow = isFeatureEnabled(featureName as Feature)
+ const trimmedFeatureName = rawFeatureName.trim()
+ const isNegated = trimmedFeatureName.startsWith('!')
+ const normalizedFeatureName = (
+ isNegated ? trimmedFeatureName.slice(1) : trimmedFeatureName
+ ).trim()
+
+ if (!normalizedFeatureName) {
+ throw new Error('$Show directive requires a non-empty feature name for the "if" attribute')
+ }
+
+ const isEnabled = isFeatureEnabled(normalizedFeatureName as Feature)
+ const shouldShow = isNegated ? !isEnabled : isEnabled
nodesToProcess.push({
node,
diff --git a/packages/common/enabled-features/enabled-features.json b/packages/common/enabled-features/enabled-features.json
index 5b3494a7850..3221a0c9812 100644
--- a/packages/common/enabled-features/enabled-features.json
+++ b/packages/common/enabled-features/enabled-features.json
@@ -80,6 +80,8 @@
"project_settings:legacy_jwt_keys": true,
"project_settings:log_drains": true,
+ "quickstarts:hide_nimbus": true,
+
"reports:all": true,
"sdk:csharp": true,
diff --git a/packages/common/enabled-features/enabled-features.schema.json b/packages/common/enabled-features/enabled-features.schema.json
index 9943b890297..cbb99e6bfb7 100644
--- a/packages/common/enabled-features/enabled-features.schema.json
+++ b/packages/common/enabled-features/enabled-features.schema.json
@@ -269,6 +269,11 @@
"description": "Enable the log drains page in project settings"
},
+ "quickstarts:hide_nimbus": {
+ "type": "boolean",
+ "description": "Whether to show the Nimbus quickstart"
+ },
+
"reports:all": {
"type": "boolean",
"description": "Enable the project reports page"
@@ -362,6 +367,7 @@
"project_connection:show_app_frameworks",
"project_connection:show_mobile_frameworks",
"project_connection:show_orms",
+ "quickstarts:hide_nimbus",
"reports:all",
"sdk:csharp",
"sdk:dart",