Limit debug logs to 4096 bytes on vercel to avoid errors#1598
Conversation
🦋 Changeset detectedLatest commit: c092747 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| @@ -1,5 +1,7 @@ | |||
| // TODO: Replace with a more sophisticated logging solution | |||
|
|
|||
| import truncate from 'truncate-utf8-bytes'; | |||
There was a problem hiding this comment.
I believe we intentionally try to mitigate usage of 3p dependencies in our packages. We can inline this pretty easily using TextEncoder and TextDecoder:
function truncate(str: string, maxLength: number) {
const encoder = new TextEncoder();
const decoder = new TextDecoder('utf-8');
const encodedString = encoder.encode(str);
const truncatedString = encodedString.slice(0, maxLength);
// return the truncated string, removing any replacement characters that result from partially truncated characters
return decoder.decode(truncatedString).replace(/\uFFFD/g, '');
}(ref)
There was a problem hiding this comment.
Happy to shift over to this, but I was reluctant to do so initially since it doesn't handle multi-byte characters, where the library I included does, and is hardly any more code overall. We could copy-paste the 3p library code too, but that seems a little silly
There was a problem hiding this comment.
@jescalan The above sort of handles the multi-byte characters by stripping out the leftovers if they get split. I see what you're saying, but let's inline for now and we can revisit the stance on dependencies as a team. The fact that our deps list is so short feels deliberate.
brkalow
left a comment
There was a problem hiding this comment.
LGTM! I think we need a patch changeset here and then it's good to go. Nice work
96c773d to
e14d271
Compare
e14d271 to
c092747
Compare
|
This PR has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Type of change
Packages affected
@clerk/clerk-js@clerk/clerk-react@clerk/nextjs@clerk/remix@clerk/types@clerk/themes@clerk/localizations@clerk/clerk-expo@clerk/backend@clerk/clerk-sdk-node@clerk/shared@clerk/fastify@clerk/chrome-extensiongatsby-plugin-clerkbuild/tooling/choreDescription
npm testruns as expected.npm run buildruns as expected.When deployed to Vercel, logs cannot exceed 4096 bytes, or no logs are displayed at all and the user gets an error instead. This PR truncates debug logs to 4096 bytes to ensure that they display correctly on Vercel.
Fixes JS-608