fix(ens): warm-cache resolved names to stop the address→name flash on mount - #2573
Conversation
…lash a cold mount (mobile reopening the pwa reloads the page) showed the raw address for a beat while the lookup ran — pay the 404, engage the client fallback, resolve, flip. persist resolved names for 24h and paint them immediately on mount while the lookup revalidates. an authoritative server "no name" evicts the entry so stale names can't mask reality.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthrough
ChangesPrimary-name cache
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Hook
participant Cache
participant Server
participant Client
Hook->>Cache: Read cached name
Hook->>Server: Request primary name
Server-->>Hook: Return name or error
Hook->>Client: Resolve fallback
Client-->>Hook: Return name or empty result
Hook->>Cache: Write or evict cache entry
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Code-analysis diffPainscore total: 6306.8 → 6307.65 (+0.85) 🆕 New findings (3)
✅ Resolved (3)
📈 Painscore deltas (top movers)
|
🧪 UI test report — ✅ all greenSuites
📊 Coverage (unit)
⏱ 10 slowest test cases
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/hooks/usePrimaryNameServer.ts`:
- Around line 36-48: Update readNameCache to validate the parsed JSON root
before returning it: only accept a non-null object, and return an empty cache
for null or other non-object values. Keep getCachedName’s existing lookup and
TTL behavior unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 4d3e75d9-5609-4448-bd54-4591c7ae2c2a
📒 Files selected for processing (2)
src/hooks/__tests__/usePrimaryNameServer.test.tsxsrc/hooks/usePrimaryNameServer.ts
coderabbit: JSON.parse('null') passes the try/catch but null[address]
throws during render. treat any non-object root as an empty cache.
…k href in sync code-review findings: (1) with the server route erroring (today's prod state) the only eviction path was server null, which never fires — a client lookup settling '' (justaname's not-found) now also masks and evicts, so a released/transferred ens name can't keep painting from cache. (2) AddressLink's effect never reset urlAddress on the name→address downgrade, leaving the href pointing at a name the address may no longer own — reachable now that cached names can be evicted mid-mount. (3) server '' responses treated same as null.
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary
Follow-up to #2565 (reported by Kush): backgrounding the app and returning reloads the page on mobile, so history briefly shows raw addresses before ENS names pop in. The in-memory react-query cache dies with the page, and every cold mount pays the
/ens/reverse404 round-trip before the client fallback resolves.Fix: persist resolved names in
localStorage(ens-primary-name-cache, 24h TTL). On mount the cached name paints immediately while the fresh lookup revalidates in the background.Staleness safety (from the multi-agent review pass):
null/'', or — critical while the backend route is undeployed — the client lookup settling''(JustaName's not-found). A released/transferred ENS name cannot keep painting from cache once a lookup settles.AddressLinknow resets its href on the name→address downgrade (pre-existing one-way effect, previously unreachable; the warm cache made it a live path). Prevents navigating to a name's new owner from a row showing the raw address."null", arrays) are treated as empty (CodeRabbit).Design notes / accepted trade-offs
storagelistener: another tab's eviction isn't observed until next mount. Accepted — display-only label, listener plumbing isn't earning its complexity.Risks / breaking changes
main→ back-merge debt (main→dev) now covers fix(history): restore ENS names via client-side fallback while /ens/reverse is undeployed #2565 + fix(withdraw): stop success receipt showing 'Sent to undefined' #2572 + this.QA
npm run typecheck✅ ·npm test✅ (2235 passed; hook suite 9 tests: warm-paint, server-null eviction, client-'' eviction, both-fail, fallbacks) · prettier ✅Screenshots: N/A (timing behavior, not layout)
Summary by CodeRabbit
New Features
Bug Fixes