Skip to content

Conversation

paddlefish
Copy link
Contributor

@paddlefish paddlefish commented Aug 8, 2023

…geError: Invalid string length" when downloading profiling

Summary:

Fixes #2050

Test Plan:

Follow steps in issue 2050

Checklist

  • Documentation is up to date to reflect these changes.
  • Follows commit message convention described in CONTRIBUTING.md


// Convert to JSON in chunks because JSON.stringify() will fail for large
// arrays with the error "RangeError: Invalid string length"
const out = events.map(JSON.stringify).join(",");
Copy link
Member

Choose a reason for hiding this comment

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

can we keep the space of 4 as in the original code?

fs.writeFileSync(
transformedFilePath,
JSON.stringify(events, undefined, 4),
"["+out+"]",
Copy link
Member

Choose a reason for hiding this comment

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

please run yarn lint --fix to fix formatting

@thymikee
Copy link
Member

Thank you for contributing a fix. Small adjustments and I think we're good to merge it

@szymonrybczak
Copy link
Collaborator

Hey @paddlefish, thanks for creating PR! If you don't have time for adjusting PR with @thymikee's suggestions - could you please allow edits from maintainers so that I can finish this PR, and we can get this merged?

Previously it could fail with the error "RangeError: Invalid string length" when downloading profiling
Fixes react-native-community#2050
@paddlefish paddlefish force-pushed the arahn/profiling-range-error branch from 1427136 to 54ad45b Compare October 9, 2023 15:02
@paddlefish
Copy link
Contributor Author

Hey @paddlefish, thanks for creating PR! If you don't have time for adjusting PR with @thymikee's suggestions - could you please allow edits from maintainers so that I can finish this PR, and we can get this merged?

Hi Szymon -- thanks for tagging me. I missed the original feedback. I had trouble running yarn lint --fix but VSCode appeared to apply the linting rules on save automatically -- so I hope that it's matching your style now.

I also added a helper function to keep it at 4-spaces. There are some other subtle differences in the format of the file (the new algorithm doesn't insert as many new lines as JSON.stringify does). I assumed this didn't matter --it's valid JSON either way.

e.g. JSON.stringify

[
    {
        "a": 1
    },
    {
        "b": 2
    }
]

The new algorithm

[{
    "a": 1
},{
    "b": 2
}]

Copy link
Collaborator

@szymonrybczak szymonrybczak left a comment

Choose a reason for hiding this comment

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

Thank you!

@szymonrybczak
Copy link
Collaborator

CI Green, @thymikee ready to merge.

@adamTrz adamTrz merged commit ae4801d into react-native-community:main Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Downloading profile data can fail with error "RangeError: Invalid string length"

4 participants