Skip to content

Conversation

@pwbriggs
Copy link

@pwbriggs pwbriggs commented Jan 4, 2024

Clarify the "I’m getting an error: “The result of getSnapshot should be cached” section of the useSyncExternalStore API reference documentation.

I put some notes about why the documented error occurs in a <DeepDive> section. It focuses on the details of comparison in JavaScript. I'm not sure if this is the intended use of deep dive sections (for example, how much prior knowledge about JavaScript do we assume the reader has? Who is the intended audience for the deep dive sections in the API reference? How well-known are the details of comparing objects in JavaScript?), but, in any case, I think this is at least an improvement.

@github-actions
Copy link

github-actions bot commented Jan 4, 2024

Size changes

Details

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

⚠️ Global Bundle Size Increased

Page Size (compressed)
global 110.55 KB (🟡 +4 B)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Five Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/404 128.05 KB (🟡 +2 B) 238.6 KB
/500 128.06 KB (🟡 +2 B) 238.61 KB
/[[...markdownPath]] 130.5 KB (🟡 +2 B) 241.05 KB
/errors 128.31 KB (🟡 +2 B) 238.86 KB
/errors/[errorCode] 128.28 KB (🟡 +2 B) 238.83 KB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 10% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

Copy link
Member

@rickhanlonii rickhanlonii left a comment

Choose a reason for hiding this comment

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

Hey @pwbriggs, thanks for the suggestion and your help elsewhere on the docs! I left some comments for improving this even more, let me know what you think!

};

console.log(object1 == object2); // false
```
Copy link
Member

@rickhanlonii rickhanlonii Jan 5, 2024

Choose a reason for hiding this comment

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

Something is missing here that connects it back to why return {} is a new object every time, something like this:


This also applies to the return values of functions:

function getUser() {
  return {
    name: "John",
    favoriteNumber: 42
  };
}

const object1 = getUser();
const object2 = getUser();

console.log(object1 == object2); // false

And maybe add an example of hosting the object out to show how it doesn't change?

Copy link
Member

Choose a reason for hiding this comment

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

The examples would be better as chat settings like in the explanations above rather than users.

Copy link
Author

Choose a reason for hiding this comment

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

@rickhanlonii I'm not sure how I should change the code example. I want it to be clear to the reader that this isn't specific to getSnapshot handlers (we include examples of that above), but it needs to include returning an object from a function (like you said).

We also want to make it clear that the values of the retuned object are the same, but then it doesn't make sense why you would be comparing the returned values.

The best I can think of is something like this:

function getMathConstants() {
  return {
    pi: 3.14159,
    e: 2.71828
  }
}

let mathConstants1 = getMathConstants();
let mathConstants2 = getMathConstants();

console.log(mathConstants1 == mathConstants2);
// false

But that makes very little sense. And, like you said, it should probably be related to the example chat app.

Any suggestions?

Copy link
Author

Choose a reason for hiding this comment

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

Update everything but the code example.
@rickhanlonii
Copy link
Member

Hey @pwbriggs, unrelated to this PR, I can't find a way to contact you. Can you email me or DM me on twitter? I appreciate all you do on the docs and I'd like to upgrade your permissions to be a maintainer if you're interested :)

@pwbriggs
Copy link
Author

Sure, thanks for the invitation! Do you have an email address you're willing to share? Do you have access to opensource@meta.com's inbox?

@rickhanlonii
Copy link
Member

Same as my GH handle at gmail

@vercel
Copy link

vercel bot commented May 11, 2024

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

Name Status Preview Comments Updated (UTC)
19-react-dev ❌ Failed (Inspect) May 12, 2024 4:04am
react-dev ✅ Ready (Inspect) Visit Preview May 12, 2024 4:04am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants