-
-
Notifications
You must be signed in to change notification settings - Fork 632
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
remove extra js eval call #1544
remove extra js eval call #1544
Conversation
railsContext: railsContext | ||
}); | ||
} finally { | ||
console.history = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alternatively, we could move this into serverRenderReactComponent
. I'll let you all decide
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, @Judahmeek @ahangarha @KhaledEmaraDev This line would be a great place to add a configurable cleanup code for SSR. For example, in the past, I saw weird side effects from MobX on SSR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wyattades I see your point that we could move console.history = [];
to here: https://github.com/shakacode/react_on_rails/blob/master/node_package/src/serverRenderReactComponent.ts#L12
One can argue that it makes sense to keep the generated JS as small as possible, so I like that solution.
@Judahmeek @alexeyr-ci what do you guys think?
I vote we:
- rename the current function
serverRenderReactComponent
to something likeserverRenderReactComponentInternal
and not export it. - Create
serverRenderReactComponent
in the same file with the try/finally block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If nobody calls serverRenderReactComponentInternal
other than serverRenderReactComponent
, why bother creating it (instead of just adding try/finally there directly)? If someone does, sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Easier to read. Function is already too long.
Awesome work @wyattades. Can you document how you profiled this? Maybe you could add such information to CONTRIBUTING.md? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work.
To merge, I'd like to see:
- Tests for the changes if easy to do.
- We need to deprecate or prevent eval_js from being called directly, as it won't clear the console.history any more.
- We need a changelog.md entry.
railsContext: railsContext | ||
}); | ||
} finally { | ||
console.history = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good solution.
Can do, probably by next week.
I don't have anything reproducible at the moment, since I tested it against a private project. But this would be as simple as running a benchmark on request durations on the dummy project. Maybe it'd be good to make a
I don't see any documentation that it's public, do we need deprecation? |
|
I checked if we have similar problems elsewhere and I don't think so (at least with react_on_rails/spec/dummy/spec/system/integration_spec.rb Lines 16 to 24 in 43efef2
but it's in tests. |
@wyattades can you also rebase on master? CI won't pass until you do since we had some of the jobs set to trigger on This oversight was corrected by #1553 |
Made a separate PR for this, since I ran into some issues with the dummy app #1555 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer to put formatting in separate PR.
b0aebd2
to
4e248cc
Compare
Nice and small update! |
Summary
The current implementation calls
ExecJS::Runtime#eval
twice during every react server-side render, but we can refactor it to only calleval
once.This causes a 2x speedup (e.g. 800ms -> 400ms) with the Node.js runtime, and other runtimes with slow IO.
Pull Request checklist
Other Information
This change is