-
-
Notifications
You must be signed in to change notification settings - Fork 628
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
Add support for replaying logs happen on async server operations #1649
base: master
Are you sure you want to change the base?
Add support for replaying logs happen on async server operations #1649
Conversation
WalkthroughThe changes involve modifications to the Changes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
Outside diff range and nitpick comments (3)
node_package/src/buildConsoleReplay.ts (3)
16-19
: Excellent change to improve robustness across different execution contexts.The replacement of
instanceof Array
withArray.isArray
is a great improvement. It addresses potential issues with prototype mismatches when the code runs in different execution contexts, such as within a VM for node rendering.The updated comments provide valuable context for this change, which enhances code maintainability.
Consider adding a brief mention of why
Array.isArray
is preferred overinstanceof Array
in the comments. This could help developers who might not be familiar with the nuances of these checks. For example:// Must use Array.isArray instead of instanceof Array the history array is defined outside the vm if node renderer is used. // In this case, the Array prototype used to define the array is not the same as the one in the global scope inside the vm. +// Array.isArray is more reliable as it works correctly even when the array is created in a different realm or execution context.
18-18
: Consider removing or replacing the Flow commentThe
// $FlowFixMe
comment is typically used for Flow type checking, but this file appears to be using TypeScript. Consider removing this comment or replacing it with a TypeScript-specific comment if type assertion is needed.If type assertion is needed, you could use a TypeScript assertion comment instead:
// @ts-ignore
Or, preferably, use a type assertion:
if (!Array.isArray(console.history as any[])) {
Line range hint
29-29
: Consider using a more specific type for the caught errorInstead of using
any
for the caught error, consider using a more specific type. This will improve type safety and make the error handling more robust.You could use the
unknown
type and then narrow it down:} catch (e: unknown) { let errorMessage = 'An error occurred'; if (e instanceof Error) { errorMessage = e.message; } val = `${errorMessage}: ${arg}`; }This approach provides better type safety and more informative error messages.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- node_package/src/buildConsoleReplay.ts (1 hunks)
- node_package/src/serverRenderReactComponent.ts (4 hunks)
Additional comments not posted (1)
node_package/src/buildConsoleReplay.ts (1)
Line range hint
1-46
: Summary of reviewThe changes made to this file improve its robustness when dealing with arrays from different execution contexts. The main functionality remains intact while addressing potential edge cases.
Key points:
- The switch to
Array.isArray
is a good improvement.- The updated comments provide valuable context for the change.
- There are opportunities for further improvements in type safety and error handling.
Overall, this change is a step in the right direction for making the code more reliable across different environments.
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
node_package/src/buildConsoleReplay.ts (2)
14-19
: Approve changes with a minor suggestion for comment improvement.The updated function signature and comment changes look good. Accepting
consoleHistory
as a parameter improves flexibility and testability. The explanation for usingArray.isArray
is valuable.Consider adding a brief explanation of why
consoleHistory
is now a parameter. For example:export function consoleReplay(consoleHistory: typeof console['history']): string { - // console.history is a global polyfill used in server rendering. + // consoleHistory is passed as a parameter to improve flexibility and testability. + // It replaces the global console.history polyfill previously used in server rendering. // Must use Array.isArray instead of instanceof Array the history array is defined outside the vm if node renderer is used. // In this case, the Array prototype used to define the array is not the same as the one in the global scope inside the vm.
44-45
: Approve changes with a suggestion for JSDoc improvement.The updates to the
buildConsoleReplay
function are consistent with the changes made toconsoleReplay
. The modification improves the flexibility of the function.Consider adding a JSDoc comment to explain the purpose of the function and its parameter. For example:
/** * Builds a console replay script wrapped in script tags. * @param consoleHistory - The console history to be replayed. * @returns A string containing the console replay script wrapped in script tags. */ export default function buildConsoleReplay(consoleHistory: typeof console['history']): string { return RenderUtils.wrapInScriptTags('consoleReplayLog', consoleReplay(consoleHistory)); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
- node_package/src/ReactOnRails.ts (1 hunks)
- node_package/src/buildConsoleReplay.ts (2 hunks)
- node_package/src/serverRenderReactComponent.ts (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- node_package/src/serverRenderReactComponent.ts
🔇 Additional comments (3)
node_package/src/buildConsoleReplay.ts (2)
19-19
: Approve the updated condition.The change from
instanceof Array
toArray.isArray
is correct and consistent with the updated comment. Using theconsoleHistory
parameter instead ofconsole.history
aligns with the function signature change.
Line range hint
1-46
: Summary of changes and alignment with PR objectives.The changes made to this file successfully contribute to the PR objective of adding support for replaying logs from async server operations. The modifications to
consoleReplay
andbuildConsoleReplay
functions improve flexibility and testability by accepting aconsoleHistory
parameter instead of relying on a global variable.Key improvements:
- Enhanced flexibility by parameterizing
consoleHistory
.- Improved reliability by using
Array.isArray
instead ofinstanceof Array
.- Updated comments explaining the rationale behind the changes.
These changes will facilitate better debugging and monitoring of async server operations by allowing more controlled log replay.
To fully complete the PR objectives, please ensure that:
- Tests are added or updated to cover these changes.
- Documentation is updated to reflect the new function signatures and usage.
- The CHANGELOG is updated with an entry for this feature.
node_package/src/ReactOnRails.ts (1)
260-260
: LGTM! Verify related changes and update tests/docs.The change to pass
console.history
tobuildConsoleReplay
aligns with the PR objective of supporting log replay for async server operations. This should improve debugging capabilities.Please ensure the following:
- The
buildConsoleReplay
function (likely in another file) has been updated to accept and use thisconsole.history
parameter.- Unit tests have been updated or added to cover this change.
- Documentation has been updated to reflect this new functionality.
To verify the
buildConsoleReplay
function update, you can run:Would you like assistance in updating the tests or documentation for this change?
Co-authored-by: Alexey Romanov <[email protected]>
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.
Overall LGTM. Just questions abuot minor details.
promiseResult = { | ||
html: await renderResult, | ||
html: awaitedRenderResult, |
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.
Why are we basically just moving the await
to line 114?
Actually, one additional question: Can we easily test these changes? |
@@ -99,7 +98,7 @@ as a renderFunction and not a simple React Function Component.`); | |||
renderingError = e; | |||
} | |||
|
|||
const consoleReplayScript = buildConsoleReplay(); | |||
const consoleHistoryAfterSyncExecution = 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.
Too confusing to use this getter...timing and globals
Could this be updated only for the pro version node renderer to return a object for the console history?
const reactRenderingResult = createReactOutput({
componentObj,
domNodeId,
trace,
props,
railsContext,
});
Summary
Remove this paragraph and provide a general description of the code changes in your pull
request... were there any bugs you had fixed? If so, mention them. If
these bugs have open GitHub issues, be sure to tag them here as well,
to keep the conversation linked together.
Pull Request checklist
Remove this line after checking all the items here. If the item is not applicable to the PR, both check it out and wrap it by
~
.Add the CHANGELOG entry at the top of the file.
Other Information
Remove this paragraph and mention any other important and relevant information such as benchmarks.
This change is
Summary by CodeRabbit
Bug Fixes
console.history
to ensure accurate console replay functionality across different execution contexts.console.history
based on the rendering outcome, ensuring it resets appropriately.New Features