fix: resolve pricing page React 19 hydration mismatch (toLocaleString + authMode) #SUPERLOG - #468
Open
superlog-app[bot] wants to merge 1 commit into
Open
fix: resolve pricing page React 19 hydration mismatch (toLocaleString + authMode) #SUPERLOG#468superlog-app[bot] wants to merge 1 commit into
superlog-app[bot] wants to merge 1 commit into
Conversation
… + authMode) #SUPERLOG Delivery-Id: 40395550a8491087bc7e3df0c53d2cd4040aaaa54d64fe6b323044ef6f4c3c87 Delivery-Base: main
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
/pricingpage was throwing React 19 hydration error #418 (text node mismatch) every time a user visited from a browser whose locale differs from the Node.js build environment. During prerendering, Node.js in a POSIX/C locale formats2_000_000as"2000000"(no commas); the user's browser (en-US) formats it as"2,000,000". React 19 detects the text node mismatch duringhydrateRootand discards the prerendered tree, causing a visible layout shift and slower page load.A secondary bug exists in the
authModeuseStatelazy initializer, which readswindow.location.hashduring render. On the server (prerender)typeof window === "undefined"is true so it returnsnull; on the client, if the URL hash containssso-callbackorverify(e.g. after SSO redirect), it returns"sign-in". Both SSR and client-hydration render must agree on the same initial state.Root cause
In
PaygEstimator, threeScaleSliderinstances calledn.toLocaleString()without a locale argument.toLocaleString()is locale-sensitive: its output is determined by the runtime's locale, which differs between the Node.js build container (typically POSIX/C) and end-user browsers (e.g. en-US). This is documented by React as a common cause of hydration mismatches.The
authModeinitializer used atypeof window === "undefined"guard, which is the canonical React SSR/CSR mismatch anti-pattern.Changes
apps/web/src/Pricing.tsx: pintoLocaleString("en-US")in all three sliderformatValuecallbacks so both SSR and browser produce identical number strings.apps/web/src/Pricing.tsx: changeauthModefrom a lazy initializer that readswindow.location.hashto a plainnullinitial state, and move the hash check intouseEffectso SSR and initial hydration render agree.Incident: eager-iguana (199724da-2620-43b1-b27c-8b171964016d)
Was this PR helpful? Leave feedback — goes straight to the Superlog team.
Summary by cubic
Fixes React 19 hydration mismatch on
/pricingby pinning number formatting to a stable locale and deferring URL-hash reads. Previously SSR rendered 2000000 and the browser rendered 2,000,000, causing React to discard the prerendered tree and a layout shift; now both sides agree andauthModeinitializes consistently.toLocaleString("en-US")for all threeScaleSliderformatValuecallbacks inapps/web/src/Pricing.tsxto make SSR and client output identical. Numbers now always display with en-US separators.authModetonulland movewindow.location.hashparsing forsso-callback/verifyintouseEffect, so hydration matches SSR and sign-in opens after mount when applicable.Written for commit 52eeba1. Summary will update on new commits.