Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export stream functions only for node bundles #1681

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions node_package/src/ReactOnRails.node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import ReactOnRails from './ReactOnRails';
import streamServerRenderedReactComponent from './streamServerRenderedReactComponent';

ReactOnRails.streamServerRenderedReactComponent = streamServerRenderedReactComponent;

export * from './ReactOnRails';
8 changes: 8 additions & 0 deletions node_package/src/ReactOnRails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,14 @@ ctx.ReactOnRails = {
return serverRenderReactComponent(options);
},

/**
* Used by server rendering by Rails
* @param options
*/
streamServerRenderedReactComponent() {
throw new Error('streamServerRenderedReactComponent is only supported when using a bundle built for Node.js environments');
},

/**
* Used by Rails to catch errors in rendering
* @param options
Expand Down
1 change: 1 addition & 0 deletions node_package/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export interface ReactOnRails {
): RenderReturnType;
getComponent(name: string): RegisteredComponent;
serverRenderReactComponent(options: RenderParams): null | string | Promise<RenderResult>;
streamServerRenderedReactComponent(options: RenderParams): Readable;
handleError(options: ErrorOptions): string | undefined;
buildConsoleReplay(): string;
registeredComponents(): Map<string, RegisteredComponent>;
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"name": "react-on-rails",
"version": "14.1.0",
"description": "react-on-rails JavaScript for react_on_rails Ruby gem",
"main": "node_package/lib/ReactOnRails.js",
"exports": {
".": {
"node": "./node_package/lib/ReactOnRails.node.js",
"default": "./node_package/lib/ReactOnRails.js"
}
},
"directories": {
"doc": "docs"
},
Expand Down
7 changes: 4 additions & 3 deletions spec/dummy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-helmet": "^6.1.0",
"react-on-rails": "file:.yalc/react-on-rails",
"react-on-rails": "link:.yalc/react-on-rails",
"react-proptypes": "^1.0.0",
"react-redux": "^8.0.2",
"react-router-dom": "^5.2.0",
Expand Down Expand Up @@ -72,12 +72,13 @@
"fs": false
},
"scripts": {
"yalc-postinstall": "yalc link react-on-rails",
"preinstall": "yarn run link-source && yalc add --link react-on-rails",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While not part of the original PR goal, this change addressed the issue of occasionally failing to utilize the latest updates in the local react-on-rails.

"link-source": "cd ../.. && yarn run build && yalc publish",
"lint": "cd ../.. && yarn run lint",
"format": "cd ../.. && yarn start format",
"test": "yarn run build:test && yarn run lint && rspec",
"build:test": "rm -rf public/webpack/test && yarn build:rescript && RAILS_ENV=test NODE_ENV=test bin/shakapacker",
"build:dev": "rm -rf public/webpack/development && yarn build:rescript && RAILS_ENV=development NODE_ENV=development bin/shakapacker --watch",
"build:dev": "rm -rf public/webpack/development && yarn build:rescript && RAILS_ENV=development NODE_ENV=development bin/shakapacker",
"build:dev:server": "rm -rf public/webpack/development && yarn build:rescript && RAILS_ENV=development NODE_ENV=development bin/shakapacker --watch",
"build:dev:watch": "rescript build -w && RAILS_ENV=development NODE_ENV=development bin/shakapacker --watch",
"build:clean": "yarn build:rescript && rm -rf public/webpack || true",
Expand Down
7 changes: 3 additions & 4 deletions spec/dummy/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6451,10 +6451,9 @@ react-is@^18.0.0:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.2.0.tgz#199431eeaaa2e09f86427efbb4f1473edb47609b"
integrity sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==

"react-on-rails@file:.yalc/react-on-rails":
version "14.0.0"
dependencies:
"@babel/runtime-corejs3" "^7.12.5"
"react-on-rails@link:.yalc/react-on-rails":
version "0.0.0"
uid ""

react-proptypes@^1.0.0:
version "1.0.0"
Expand Down
Loading