A React 18 renderer for ServiceNow UI Framework that provides seamless integration with Next Experience components.
- React 18 Support: Full compatibility with React 18 hooks and concurrent features
- Automatic Setup: One-command installation that handles all configuration
- Babel Plugin Patching: Automatically patches ServiceNow's babel plugin for React support
- Drop-in Replacement: Compatible with existing ServiceNow React patterns
- Error Boundaries: Built-in error handling for React components
- VNode Filtering: Prevents Snabbdom VNode contamination
- No Manual Configuration: Zero manual babel plugin modifications required
# Install the package
npm install @quixomatic/ui-renderer-react-simple react@18 react-dom@18
# Run the setup script (creates fake package + patches babel)
npx setup-servicenow-react
# Complete the setup
npm install
npx setup-servicenow-react
- Complete setup (fake package + babel patch)npx patch-servicenow-babel
- Just patch the babel pluginnpx restore-servicenow-babel
- Restore original babel plugin
After setup, you can use React components exactly like you would with the original @quixomatic/ui-renderer-react
:
// my-component/index.js
import { createCustomElement } from "@servicenow/ui-core";
import react from "@servicenow/ui-renderer-react";
import view from "./view";
import styles from "./styles.scss";
createCustomElement("my-react-component", {
renderer: { type: react },
view,
properties: {
title: { default: "Hello World" },
count: { default: 0 }
},
actionHandlers: {
INCREMENT: ({ state, updateProperties }) => {
updateProperties({ count: state.properties.count + 1 });
}
},
styles
});
// my-component/view.js
import React, { useState } from "react";
export default function MyReactComponent(state) {
const { dispatch, helpers, properties } = state;
const { title, count } = properties;
const [localState, setLocalState] = useState('');
const handleClick = () => {
dispatch('INCREMENT');
setLocalState('Button clicked!');
};
return (
<div>
<h1>{title}</h1>
<p>Count: {count}</p>
<button onClick={handleClick}>Increment</button>
<p>{localState}</p>
</div>
);
}
This package solves the JSX transformation problem in ServiceNow by:
- Installing as a regular npm package (
@quixomatic/ui-renderer-react-simple
) - Creating a fake local package (
@servicenow/ui-renderer-react
) that tricks the babel plugin - Automatically patching ServiceNow's babel plugin to handle React renderers correctly
- Providing React 18 compatibility while maintaining the same API
- Filtering VNode objects to prevent React rendering errors
- Creates
src/node_modules/@servicenow/ui-renderer-react/
directory - Copies the renderer files to masquerade as the official ServiceNow renderer
- Updates your
package.json
to include the local dependency - Automatically patches the ServiceNow babel plugin in
~/.snc/.extensions/ui-component/
- Creates a backup of the original babel plugin for easy restoration
- Ensures React 18 dependencies are present
The setup script automatically:
- Locates ServiceNow's babel plugin file
- Creates a backup before making changes
- Patches the React renderer configuration to use the correct module path
- Removes any old renderer entries
- Verifies the patch was applied successfully
If needed, you can manually control the babel plugin:
# Patch just the babel plugin
npx patch-servicenow-babel
# Restore the original babel plugin
npx restore-servicenow-babel
If you're migrating from the original @quixomatic/ui-renderer-react
:
- Remove the old package:
npm uninstall @quixomatic/ui-renderer-react
- Install this package:
npm install @quixomatic/ui-renderer-react-simple
- Run setup:
npx setup-servicenow-react
- Update imports: Change imports to
@servicenow/ui-renderer-react
- No other changes needed - your components will work exactly the same
- No manual babel modifications - everything is automated
- Automatic babel plugin patching - works out of the box
- Easy restoration - restore original babel plugin anytime
- Better error handling - improved setup process with fallbacks
This usually means the setup didn't complete properly:
- Verify the setup script ran successfully
- Check that
@servicenow/ui-renderer-react
appears in yourpackage.json
- Ensure
src/node_modules/@servicenow/ui-renderer-react/
exists - Run
npm install
again - Try running
npx patch-servicenow-babel
separately
If babel patching fails:
- Check that ServiceNow CLI is installed:
snc --version
- Verify the babel plugin exists:
npx patch-servicenow-babel
- Try restoring and re-patching:
npx restore-servicenow-babel && npx patch-servicenow-babel
Ensure you're using React 18:
npm list react react-dom
Both should show version 18.x.x.
If the automatic setup fails, you can set up manually:
-
Create the directory:
mkdir -p src/node_modules/@servicenow/ui-renderer-react
-
Copy the renderer:
cp node_modules/@quixomatic/ui-renderer-react-simple/index.js src/node_modules/@servicenow/ui-renderer-react/
-
Create package.json:
{ "name": "@servicenow/ui-renderer-react", "version": "2.0.0", "main": "index.js", "peerDependencies": { "react": "^18.0.0", "react-dom": "^18.0.0" } }
-
Add to your package.json:
{ "dependencies": { "@servicenow/ui-renderer-react": "file:src/node_modules/@servicenow/ui-renderer-react" } }
-
Run npm install
-
Patch babel manually:
npx patch-servicenow-babel
- Node.js 16+
- React 18.x
- ServiceNow Next Experience UI Framework
- ServiceNow CLI (
snc
)
MIT
Issues and pull requests are welcome on GitHub.
For support, please open an issue on GitHub or contact the maintainer.
- Added automatic babel plugin patching
- Added CLI commands for patch/restore operations
- Improved setup process with better error handling
- Added backup/restore functionality for babel plugin
- Initial release with fake package approach
- React 18 compatibility
- VNode filtering
- Error boundaries