Skip to content

PR closed due to unresolved review loop #8021

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

Closed
wants to merge 7 commits into from

Conversation

nitin-is-me
Copy link
Contributor

@nitin-is-me nitin-is-me commented Jul 25, 2025

Description

This PR improves the fetch.md documentation by fixing and clarifying key code examples related to streaming, async usage, and response handling. These are the changes I made:

  • Correctly buffers and parses the full streaming response in the Undici example, avoiding parsing incomplete chunks.
  • Adds proper try/catch handling in the stream’s final block to handle JSON parse errors.
  • Adds an inline explanation of the TextDecoder stream option to reduce confusion.

Related Issues

N/A

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run pnpm format to ensure the code follows the style guide.
  • I have run pnpm test to check if all tests are passing. (N/A)
  • I have run pnpm build to check if the website builds without errors. (N/A)
  • I've covered new added functionality with unit tests if necessary. (N/A)

@nitin-is-me nitin-is-me requested a review from a team as a code owner July 25, 2025 02:42
Copy link

vercel bot commented Jul 25, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
nodejs-org ✅ Ready (Inspect) Visit Preview Jul 26, 2025 0:40am

@avivkeller
Copy link
Member

I don't see how this is an improvement to our previous page

@nitin-is-me
Copy link
Contributor Author

@avivkeller Let me explain why these changes are improvements. Each commit addresses a concrete issue in the examples or improves clarity where it previously led to confusion:


  1. fix(docs): correct response structure comment in GET example:

    Original comment incorrectly showed a single object as the response, while the actual response from the API is an array of objects.
    I updated the comment to wrap the object in square brackets to reflect the actual return structure:

    // [
    //   { userId: 1, id: 1, ... }
    // ]
    
  2. fix(docs): explain top-level await usage and fallback in fetch example:

    The example uses top-level await, but without context, this can cause a SyntaxError for users in CommonJS environments.
    I clarified that top-level await requires ES modules (.mjs or "type": "module") and also added a fallback using an async IIFE:

    (async () => {
    await ...
    })();
    
  3. fix(docs): handle streaming JSON parsing properly in fetch example:

    The original stream handling attempted to parse chunks directly or didn’t account for chunk boundaries, so
    I introduced buffering and moved JSON.parse into the .final() block of the Writable stream, where the full body is guaranteed to be available:

    final(callback) {
    const json = JSON.parse(buffer);
    }
    
  4. fix(docs): add comment explaining TextDecoder stream option

    The line used decoder.decode(chunk, { stream: true }) without explanation which could be confusing to devs or readers, so I added a short but critical comment clarifying that the stream: true option may buffer incomplete UTF-8 sequences, which affects chunk-wise console logging or string building:

    // Note: decoder.decode() with { stream: true } may buffer incomplete UTF-8 chunks.
    

    This helps readers understand why a chunk might appear missing or cut off when logged directly.

    Each of these changes is small but meaningful, aimed at making the examples clearer, more accurate, and more beginner friendly. Happy to revise anything further if needed! :D

@AugustinMauroy
Copy link
Member

fix(docs): explain top-level await usage and fallback in fetch example:

You can use code tabs for CJS/ESM

@nitin-is-me
Copy link
Contributor Author

nitin-is-me commented Jul 25, 2025

You can use code tabs for CJS/ESM

Am I mistaken, or there are no code tabs to switch between CJS and ESM in the fetch documentation?:

image

This is the code I'm changing, the default one will give SyntaxError:

image

@nitin-is-me
Copy link
Contributor Author

Hello everyone! I'm going to update the fetch.md file so that it contains tabs for both CJS and ESM, keeping the rest changes as it is. This will not take much!

@nitin-is-me nitin-is-me changed the title fix(docs): improve fetch examples with accurate usage, error handling, and streaming clarity fix(docs): improve fetch examples with proper streaming, error handling, and dual CJS/ESM usage Jul 25, 2025
@nitin-is-me
Copy link
Contributor Author

nitin-is-me commented Jul 25, 2025

Update: Added missing dual tab support (CommonJS and ES Modules) for the streaming examples in fetch documentation.

Copy link
Member

@AugustinMauroy AugustinMauroy left a comment

Choose a reason for hiding this comment

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

LGMT !

Copy link
Member

@avivkeller avivkeller left a comment

Choose a reason for hiding this comment

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

This is still doing several things. For example, If we want to add CJS/ESM interop, it should be it's own PR.

@avivkeller
Copy link
Member

Let's do the fixes in one PR, and the addition/features in another

@nitin-is-me
Copy link
Contributor Author

@avivkeller Acknowledged, working on it!

@nitin-is-me
Copy link
Contributor Author

nitin-is-me commented Jul 26, 2025

Tab changes were reverted, it will be submitted separately in another PR. This one now only includes small fixes and clarification changes to the fetch example. Changes were made on top of the latest main branch.

@nitin-is-me nitin-is-me changed the title fix(docs): improve fetch examples with proper streaming, error handling, and dual CJS/ESM usage fix(docs): improve fetch examples with proper streaming and error handling Jul 26, 2025
@nitin-is-me
Copy link
Contributor Author

nitin-is-me commented Jul 26, 2025

Tab additions have been separated out into a new PR (#8035) to keep changes focused. That PR builds on top of the updates made here. In case any conflicts occur, then I'm happy to rebase the branch of that PR (fetch-tabs) on top of main once this PR is merged, tag me anytime!

@nitin-is-me
Copy link
Contributor Author

Hey @avivkeller @AugustinMauroy 👋
Just wanted to bump this PR, and #8035 (Separated for adding feature) in case it slipped under the radar. Let me know if any changes are needed. Appreciate your time!

@@ -181,4 +181,4 @@ async function fetchGitHubRepos() {
}

fetchGitHubRepos().catch(console.error);
```
```
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
```
```

Comment on lines 169 to -174
} catch (error) {
console.error('Error parsing JSON:', error);
} finally {
console.log('Stream processing completed.');
callback();
}

callback();
},
final(callback) {
console.log('Stream processing completed.');
callback();
Copy link
Member

Choose a reason for hiding this comment

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

The point of this demo is to showcase the callback, let's not change it to a try final

Copy link
Collaborator

Choose a reason for hiding this comment

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

agree with aviv here - sometimes we choose to show code concepts in isolation even if a production app would have far more rigor

@@ -155,23 +157,21 @@ async function fetchGitHubRepos() {
return new Writable({
write(chunk, encoding, callback) {
buffer += chunk.toString();

callback();
Copy link
Member

Choose a reason for hiding this comment

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

Why was this added?

Comment on lines 116 to +117
partial += decoder.decode(chunk, { stream: true });
// Note: decoder.decode() with { stream: true } may buffer incomplete UTF-8 chunks.
Copy link
Member

Choose a reason for hiding this comment

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

Is this relevant to the code snippet?

  1. comments go above the block

@nitin-is-me
Copy link
Contributor Author

nitin-is-me commented Jul 29, 2025

@avivkeller Alright, I’ve already explained everything above and responded to all the points, but it’s starting to feel it’s just going in circles or not really being read. So I’m gonna close this PR, along with the other one that depended on it.
No hard feelings, just don’t wanna keep chasing something that’s clearly not moving forward.

@nitin-is-me nitin-is-me deleted the fetch-fix branch July 29, 2025 02:21
@bmuenzenmeyer
Copy link
Collaborator

i hope you find ways to continue contributing, I felt as if review feedback was responsive here.

@nitin-is-me nitin-is-me changed the title fix(docs): improve fetch examples with proper streaming and error handling PR closed due to unresolved review loop Jul 29, 2025
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.

4 participants