Skip to content

Commit

Permalink
React server component support (#121)
Browse files Browse the repository at this point in the history
* Add 'use client' to each file that interacts with a rollbar context
* Add rollup plugin to preserve use client directives
  • Loading branch information
matux authored Mar 21, 2024
1 parent 997735a commit 17a46d9
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/nextjs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/react-17/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/typescript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"rollbar": "^2.26.3",
"rollup": "^4.12.0",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-preserve-directives": "^0.4.0",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"typescript": "^5",
Expand Down
32 changes: 29 additions & 3 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import resolve from '@rollup/plugin-node-resolve';
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import babel from '@rollup/plugin-babel';
import pkg from './package.json' assert { type: 'json' };
import preserveDirectives from 'rollup-plugin-preserve-directives';

const COMMON_PLUGINS = [
resolve(),
Expand All @@ -14,6 +15,22 @@ const COMMON_PLUGINS = [
babel({ babelHelpers: 'bundled', exclude: ['node_modules/**'] }),
];

const entryFileNames = (chunkInfo) => {
if (chunkInfo.name.includes('node_modules')) {
return chunkInfo.name.replace(/node_modules/g, 'external') + '.js';
}

return '[name].js';
};

const onwarn = (warning, warn) => {
if (warning.code === 'MODULE_LEVEL_DIRECTIVE') {
return;
}

warn(warning);
};

export default [
{
input: 'src/index.js',
Expand All @@ -30,6 +47,7 @@ export default [
},
},
plugins: [...COMMON_PLUGINS, commonjs()],
onwarn,
},

{
Expand All @@ -51,16 +69,24 @@ export default [
dir: pkg.module,
format: 'es',
sourcemap: true,
entryFileNames: '[name].js',
preserveModules: true,
preserveModulesRoot: 'src',
entryFileNames,
},
{
dir: pkg.main,
format: 'cjs',
sourcemap: true,
entryFileNames: '[name].js',
exports: 'named',
preserveModules: true,
preserveModulesRoot: 'src',
entryFileNames
},
],
plugins: [...COMMON_PLUGINS],
plugins: [
...COMMON_PLUGINS,
preserveDirectives({ suppressPreserveModulesWarning: true }),
],
onwarn,
},
];
2 changes: 2 additions & 0 deletions src/error-boundary.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import invariant from 'tiny-invariant';
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/use-rollbar-capture-event.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { useEffect } from 'react';
import invariant from 'tiny-invariant';
import { LEVEL_INFO } from '../constants';
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/use-rollbar-config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { useRollbar } from './use-rollbar';

export function useRollbarConfiguration(config) {
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/use-rollbar-context.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import invariant from 'tiny-invariant';
import { useEffect, useLayoutEffect } from 'react';
import { useRollbar } from './use-rollbar';
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/use-rollbar-logs.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

// EXPERIMENTAL
// NOT EXPORTED AS PART OF PUBLIC API YET
// NO TEST COVERAGE
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/use-rollbar-person.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { useRollbarConfiguration } from './use-rollbar-config';

export function useRollbarPerson(person) {
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/use-rollbar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { useContext } from 'react';
import { Context, getRollbarFromContext } from '../provider';

Expand Down
2 changes: 2 additions & 0 deletions src/hooks/use-scoped-rollbar-config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

// EXPERIMENTAL
// NOT EXPORTED AS PART OF PUBLIC API YET
// NO TEST COVERAGE
Expand Down
2 changes: 2 additions & 0 deletions src/provider.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import React, { Component, createContext } from 'react';
import PropTypes from 'prop-types';
import Rollbar from 'rollbar';
Expand Down
2 changes: 2 additions & 0 deletions src/rollbar-configuration.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

// EXPERIMENTAL
// NOT EXPORTED AS PART OF PUBLIC API YET: no current test coverage

Expand Down
2 changes: 2 additions & 0 deletions src/rollbar-context.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import { Component } from 'react';
import PropTypes from 'prop-types';
import { Context, getRollbarFromContext } from './provider';
Expand Down

0 comments on commit 17a46d9

Please sign in to comment.