Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
"types": "./dist/index.d.ts",
"exports": {
".": {
"react-server": {
"types": "./dist/server.d.ts",
"import": "./dist/server.es.min.mjs",
"default": "./dist/server.es.min.mjs"
},
"types": "./dist/index.d.ts",
"import": "./dist/react-sdk.es.min.mjs",
"default": "./dist/react-sdk.es.min.mjs"
Expand Down
29 changes: 22 additions & 7 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,28 @@ const { dependencies, peerDependencies } = pkg;
const externalDeps = [...Object.keys(dependencies || {}), ...Object.keys(peerDependencies || {}), 'crypto'];
const external = (id) => externalDeps.some((dep) => id === dep || id.startsWith(dep + '/'));

export default {
input: '.build/index.js',
const shared = {
external,
plugins: [resolve({ browser: true }), terser()],
output: {
file: 'dist/react-sdk.es.min.mjs',
format: 'es',
sourcemap: true,
},
};

export default [
{
...shared,
input: '.build/index.js',
output: {
file: 'dist/react-sdk.es.min.mjs',
format: 'es',
sourcemap: true,
},
},
{
...shared,
input: '.build/server.js',
output: {
file: 'dist/server.es.min.mjs',
format: 'es',
sourcemap: true,
},
},
];
46 changes: 46 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright 2026 Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Server-safe entry point for @optimizely/react-sdk.
*
* This module can be safely imported in React Server Components (RSC)
* as it does not use any client-only React APIs (createContext, hooks, etc.).
*/

// Client creation
export {
createInstance,
createPollingProjectConfigManager,
createStaticProjectConfigManager,
createBatchEventProcessor,
createForwardingEventProcessor,
createOdpManager,
createVuidManager,
createErrorNotifier,
} from './client/index';

// Logger
export { createLogger, DEBUG, ERROR, WARN, INFO } from './logger/index';

// Helpers
export { getQualifiedSegments, type QualifiedSegmentsResult } from './utils/helpers';

// Types from JS SDK
export type * from '@optimizely/optimizely-sdk';

// UserInfo type (type-only, safe for server)
export type { UserInfo } from './provider/types';
Loading