-
-
Notifications
You must be signed in to change notification settings - Fork 637
Reduce bundle size #1697
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
Reduce bundle size #1697
Changes from all commits
6b4a0a0
a823bc0
cbcbeed
5f0bdf7
ff0ba72
7d45d41
03f9aa3
7b392db
74b326e
17ba351
7b28810
b411f06
bbf3274
29889db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ yalc.lock | |
|
||
# IDE | ||
.idea/ | ||
.vscode/ | ||
|
||
# TypeScript | ||
*.tsbuildinfo |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import handleError from './handleError'; | ||
import serverRenderReactComponent from './serverRenderReactComponent'; | ||
import type { | ||
RenderParams, | ||
RenderResult, | ||
ErrorOptions, | ||
} from './types'; | ||
|
||
import Client from './ReactOnRails.client'; | ||
|
||
if (typeof window !== 'undefined') { | ||
console.log('Optimization opportunity: "react-on-rails" includes ~14KB of server-rendering code. Browsers may not need it. See https://forum.shakacode.com/t/how-to-use-different-versions-of-a-file-for-client-and-server-rendering/1352 (Requires creating a free account)'); | ||
} | ||
|
||
/** | ||
* Used by Rails to catch errors in rendering | ||
* @param options | ||
*/ | ||
Client.handleError = (options: ErrorOptions): string | undefined => handleError(options); | ||
|
||
/** | ||
* Used by server rendering by Rails | ||
* @param options | ||
*/ | ||
Client.serverRenderReactComponent = (options: RenderParams): null | string | Promise<RenderResult> => serverRenderReactComponent(options); | ||
|
||
export * from "./types"; | ||
export default Client; | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import ReactOnRails from './ReactOnRails'; | ||
import ReactOnRails from './ReactOnRails.full'; | ||
import streamServerRenderedReactComponent from './streamServerRenderedReactComponent'; | ||
|
||
ReactOnRails.streamServerRenderedReactComponent = streamServerRenderedReactComponent; | ||
|
||
export * from './ReactOnRails'; | ||
export { default } from './ReactOnRails'; | ||
export * from './ReactOnRails.full'; | ||
export { default } from './ReactOnRails.full'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,9 +25,9 @@ scripts: | |
# 3. Check if the project is built now; | ||
# 4. If it failed, print an error message (still follow https://docs.npmjs.com/cli/v8/using-npm/scripts#best-practices). | ||
script: > | ||
[ -f node_package/lib/ReactOnRails.js ] || | ||
[ -f node_package/lib/ReactOnRails.full.js ] || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainVerify the new file path aligns with the export split. The file check has been updated from Also applies to: 30-30 🏁 Script executed: #!/bin/bash
# Description: Verify the existence and exports of the new file.
# Check if the new file exists in the expected location
if [ -f "node_package/lib/ReactOnRails.full.js" ]; then
echo "File exists at the expected location"
else
echo "File not found at the expected location"
fi
# Check for any remaining references to the old file
rg -l "ReactOnRails\.js" --type js --type json --type yaml Length of output: 200 Missing File: Expected "ReactOnRails.full.js" Was Not Found Our verification check indicates that the file at
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's autogenerated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Romex91 Understood, thank you for the clarification. ✏️ Learnings added
If you found this review helpful, would you consider giving us a shout-out on X? |
||
(npm run build >/dev/null 2>&1 || true) && | ||
[ -f node_package/lib/ReactOnRails.js ] || | ||
[ -f node_package/lib/ReactOnRails.full.js ] || | ||
{ echo 'Building react-on-rails seems to have failed!'; } | ||
|
||
format: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,9 @@ | |
"exports": { | ||
".": { | ||
"node": "./node_package/lib/ReactOnRails.node.js", | ||
"default": "./node_package/lib/ReactOnRails.js" | ||
} | ||
"default": "./node_package/lib/ReactOnRails.full.js" | ||
}, | ||
"./client": "./node_package/lib/ReactOnRails.client.js" | ||
Comment on lines
8
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainLGTM! Effective bundle size optimization. The separation of client and server exports effectively prevents server-rendering code from being included in the browser bundle, supporting the 14KB size reduction goal. Run this script to verify the export paths: 🏁 Script executed: #!/bin/bash
# Description: Verify the existence and content of the export files
# Check if the export files exist
ls -l node_package/lib/ReactOnRails.{node,full,client}.js || echo "Missing export files"
# Check file sizes to confirm bundle size reduction
du -h node_package/lib/ReactOnRails.{node,full,client}.js Length of output: 812 Attention: Missing Export Files It appears that the export paths in
However, the verification script indicates that these files are missing. Please verify whether:
This review comment cannot be approved until the discrepancy is resolved. |
||
}, | ||
"directories": { | ||
"doc": "docs" | ||
|
Uh oh!
There was an error while loading. Please reload this page.