7 Commits

Author SHA1 Message Date
Bas
14a5acd222 Merge pull request #13 from xtr-dev/dev
Dev
2025-10-03 19:57:05 +02:00
d3b8a8446e . 2025-10-03 19:56:55 +02:00
7dc17bc80a v0.0.17: Add enableCustomListView option 2025-10-03 19:53:01 +02:00
b642b653d0 Add enableCustomListView option
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-03 19:52:57 +02:00
Bas
1db434e701 Merge pull request #12 from xtr-dev/dev
Dev
2025-10-03 19:20:09 +02:00
7fd6194712 v0.0.16: Rebuild to sync dist with source 2025-10-03 19:19:41 +02:00
259599ddcc v0.0.15: Fix SSR warning in client components
Removes misleading warning that appeared during Next.js SSR:
- Client components are initially rendered on server where window is undefined
- This is expected behavior and doesn't require a warning
- Now silently falls back to relative URLs during SSR
- Properly uses window.location.origin once hydrated on client

The hooks now work seamlessly in:
- Pure client-side apps
- Next.js with SSR/SSG
- Server components (with explicit serverURL)
- Client components (auto-detects after hydration)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-03 18:48:46 +02:00
4 changed files with 40 additions and 17 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "payload-feature-flags",
"version": "1.0.0",
"version": "0.0.17",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "payload-feature-flags",
"version": "1.0.0",
"version": "0.0.17",
"license": "MIT",
"devDependencies": {
"@eslint/eslintrc": "^3.2.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@xtr-dev/payload-feature-flags",
"version": "0.0.14",
"version": "0.0.17",
"description": "Feature flags plugin for Payload CMS - manage feature toggles, A/B tests, and gradual rollouts",
"license": "MIT",
"type": "module",

View File

@@ -21,23 +21,31 @@ export interface FeatureFlagOptions {
// Helper to get config from options or defaults
function getConfig(options?: FeatureFlagOptions) {
// In server-side environments, serverURL must be explicitly provided
const serverURL = options?.serverURL ||
(typeof window !== 'undefined' ? window.location.origin : undefined)
if (!serverURL) {
console.warn(
'FeatureFlags: serverURL must be provided when using hooks in server-side environment. ' +
'Falling back to relative URL which may not work correctly.'
)
// Use relative URL as fallback - will work if API is on same domain
return { serverURL: '', apiPath: options?.apiPath || '/api', collectionSlug: options?.collectionSlug || 'feature-flags' }
// Check if serverURL is explicitly provided
if (options?.serverURL) {
return {
serverURL: options.serverURL,
apiPath: options.apiPath || '/api',
collectionSlug: options.collectionSlug || 'feature-flags'
}
}
const apiPath = options?.apiPath || '/api'
const collectionSlug = options?.collectionSlug || 'feature-flags'
// In browser environment, use window.location.origin
if (typeof window !== 'undefined') {
return {
serverURL: window.location.origin,
apiPath: options?.apiPath || '/api',
collectionSlug: options?.collectionSlug || 'feature-flags'
}
}
return { serverURL, apiPath, collectionSlug }
// During SSR or in non-browser environments, use relative URL
// This will work for same-origin requests
return {
serverURL: '',
apiPath: options?.apiPath || '/api',
collectionSlug: options?.collectionSlug || 'feature-flags'
}
}
/**

View File

@@ -34,6 +34,11 @@ export type PayloadFeatureFlagsConfig = {
* Override collection configuration
*/
collectionOverrides?: CollectionOverrides
/**
* Enable custom list view for feature flags
* @default false
*/
enableCustomListView?: boolean
}
export const payloadFeatureFlags =
@@ -44,6 +49,7 @@ export const payloadFeatureFlags =
defaultValue = false,
enableRollouts = true,
enableVariants = true,
enableCustomListView = false,
collectionOverrides,
} = pluginOptions
@@ -163,6 +169,15 @@ export const payloadFeatureFlags =
useAsTitle: 'name',
group: 'Configuration',
description: 'Manage feature flags for your application',
components: enableCustomListView ? {
...collectionOverrides?.admin?.components,
views: {
...collectionOverrides?.admin?.components?.views,
list: {
Component: '@xtr-dev/payload-feature-flags/views#FeatureFlagsView'
}
}
} : collectionOverrides?.admin?.components || {},
...(collectionOverrides?.admin || {}),
},
fields,