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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Root Gemfile.lock (delegates to react_on_rails/Gemfile, lock is there)
/Gemfile.lock

.bundle/
/.yardoc
/_yardoc/
Expand Down
2 changes: 1 addition & 1 deletion packages/react-on-rails-pro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"clean": "rm -rf ./lib",
"test": "pnpm run test:non-rsc && pnpm run test:rsc",
"test:non-rsc": "jest tests --testPathIgnorePatterns=\".*(RSC|stream|registerServerComponent|serverRenderReactComponent|SuspenseHydration).*\"",
"test:rsc": "echo 'TODO: RSC tests disabled - jest.setup.js uses require() incompatible with ESM mode. Re-enable after converting setup to ESM.' && exit 0",
"test:rsc": "node scripts/check-react-version.cjs || NODE_CONDITIONS=react-server jest tests/*.rsc.test.*",
"type-check": "tsc --noEmit --noErrorTruncation",
"prepare": "[ -f lib/ReactOnRails.full.js ] || (rm -rf ./lib && tsc)",
"prepublishOnly": "pnpm run build",
Expand Down
19 changes: 19 additions & 0 deletions packages/react-on-rails-pro/scripts/check-react-version.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Check if React version supports RSC features (React 19+).
* Exits with code 0 if React < 19 (skip RSC tests).
* Exits with code 1 if React >= 19 (run RSC tests).
*
* This is a CommonJS file (.cjs) because it needs to use require()
* and the parent package has "type": "module".
*/
const v = require('react/package.json').version;

const majorVersion = parseInt(v, 10);

if (majorVersion < 19) {
console.log(`RSC tests skipped (requires React 19+, found ${v})`);
process.exit(0);
}

// Exit with code 1 so the || chain continues to run Jest
process.exit(1);
12 changes: 5 additions & 7 deletions packages/react-on-rails-pro/tests/jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import { TextEncoder, TextDecoder } from 'util';
import { Readable } from 'stream';
import { ReadableStream, ReadableStreamDefaultReader } from 'stream/web';
import { jest } from '@jest/globals';

// If jsdom environment is set and TextEncoder is not defined, then define TextEncoder and TextDecoder
// The current version of jsdom does not support TextEncoder and TextDecoder
// The following code will tell us when jsdom supports TextEncoder and TextDecoder
Expand All @@ -11,13 +16,6 @@ if (typeof window !== 'undefined' && typeof window.MessageChannel !== 'undefined
}

if (typeof window !== 'undefined') {
// eslint-disable-next-line global-require
const { TextEncoder, TextDecoder } = require('util');
// eslint-disable-next-line global-require
const { Readable } = require('stream');
// eslint-disable-next-line global-require
const { ReadableStream, ReadableStreamDefaultReader } = require('stream/web');

// Mock the fetch function to return a ReadableStream instead of Node's Readable stream
// This matches browser behavior where fetch responses have ReadableStream bodies
// Node's fetch and polyfills like jest-fetch-mock return Node's Readable stream,
Expand Down
8 changes: 2 additions & 6 deletions script/convert
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,8 @@ gsub_file_content(
'"test:non-rsc": "jest tests --testPathIgnorePatterns=\".*(RSC|stream|' \
'registerServerComponent|serverRenderReactComponent|SuspenseHydration).*\"",'
)
# Make test:rsc script do nothing
gsub_file_content(
"../packages/react-on-rails-pro/package.json",
/"test:rsc": "(?:\\"|[^"])*",/,
'"test:rsc": "exit 0",'
)
# test:rsc script now automatically detects React version and skips on React 18
# No override needed - the script checks React version and exits cleanly if < 19
# Keep modern JSX transform for React 18+
# gsub_file_content("../tsconfig.json", "react-jsx", "react")
# gsub_file_content("../spec/dummy/babel.config.js", "runtime: 'automatic'", "runtime: 'classic'")
Expand Down
Loading