Skip to content

fix(home): render the developer count in the server HTML - #241

Open
thzgajendra wants to merge 2 commits into
gofr-dev:mainfrom
thzgajendra:fix/homepage-developer-count
Open

thzgajendra wants to merge 2 commits into
gofr-dev:mainfrom
thzgajendra:fix/homepage-developer-count

Conversation

@thzgajendra

Copy link
Copy Markdown

Description:

Fixes #235.

The problem (in plain words)

The homepage says "Trusted by 21,500+ Developers" in a browser, but the HTML the server sends says "Trusted by 0+ Developers". The number is a count-up animation that starts at 0, and the starting value was also what got written into the page. Search engines, AI tools and anything that does not run JavaScript read the raw HTML, so they see a project with no users.

How this fixes it

The count-up component now starts with the real number instead of 0, so the server-rendered HTML contains 21,500+. In the browser, when the number scrolls into view it still counts up from 0 to 21,500 as before. People who prefer reduced motion see the final number with no animation, as before. Only src/components/CountUp.jsx changes (the homepage trusted-by list is its only user).

Diagram

flowchart LR
  subgraph Before
    A1[Server renders page] --> B1["HTML: 0+"] --> C1[Browser animates 0 to 21,500]
  end
  subgraph After
    A2[Server renders page] --> B2["HTML: 21,500+"] --> C2[Browser scrolls into view, animates 0 to 21,500]
  end
Loading

Breaking Changes (if applicable):

None. The component's props are unchanged and the animation looks the same in a browser.

Additional Information:

How I tested it

Built the site (yarn install --frozen-lockfile && yarn build) on main and on this branch and read out/index.html (the same file curl returns for the deployed site):

main:        Trusted by <span>0+</span> Developers at Companies Like:
this branch: Trusted by <span>21,500+</span> Developers at Companies Like:

Served the built branch output and drove it in a real browser (Playwright): the heading is 21,500+ on load, then after scrolling it into view the count goes 10,231+, 16,704+, 20,056+, 21,311+ and ends at 21,500+, so the animation still runs.

Coverage

Not applicable: this repository has no unit test suite and the change is one component. Verified through the build output and browser run above.

Checklist:

  • I have formatted my code using goimports and golangci-lint. (No Go code in this repo.)
  • All new code is covered by unit tests. (No test suite in this repo; verified by build output and a browser run, see above.)
  • This PR does not decrease the overall code coverage.
  • I have reviewed the code comments and documentation for clarity.

@Umang01-hash Umang01-hash left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed at head 4d86539. The fix does what it claims — I built the static export and the server HTML now contains the real count 21,500+ instead of 0+ (confirmed by reverting just the useState line, which brings 0+ back). Initial state = value on both server and client, so the common case hydrates cleanly.

One change before merge: the count renders via n.toLocaleString() with no fixed locale. Previously the server rendered 0 (locale-invariant) so hydration always matched; now the server bakes the locale-formatted number at build time (Node → 21,500), but a non-en-US browser hydrates and recomputes toLocaleString() → e.g. 21.500 (de-DE) → a React hydration text mismatch. It's cosmetic (React recovers on the client) but hits non-en-US visitors. One-line fix: pin the locale — (n) => `${n.toLocaleString('en-US')}+` (and the default x.toLocaleString('en-US') in CountUp). Happy to approve with that in.

FYI this repo has no ESLint config and CI runs only snyk (no build/lint/test), so none of this is caught automatically.

@thzgajendra

Copy link
Copy Markdown
Author

@Umang01-hash Fixed in 2a60e5e: pinned both toLocaleString calls to 'en-US' (the CompanyTrustedList format and the CountUp default).

Checked on a static export in fresh browser contexts:

Build Locale Rendered React errors
before fix de-DE 21.500+ #425, #418, #423
before fix en-US 21,500+ none
after fix de-DE 21,500+ none
after fix en-US 21,500+ none
after fix fr-FR 21,500+ none

#423 means React dropped hydration and client-rendered the page, so the mismatch was a bit more than cosmetic. The count-up animation still runs after the fix (de-DE mid-animation showed 1,144+, then settled on 21,500+), and the server HTML still contains 21,500+.

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.

Homepage HTML shows "Trusted by 0+ Developers" to crawlers

2 participants