Skip to content

fix(utils): add SSR guard to timeSync module-level localStorage access #59

Description

@tmdeveloper007

Summary of What Needs to be Done

src/utils/timeSync.js reads from localStorage at module initialization time (top-level code in the module scope) without checking if the code is running in a server-side rendering environment. In Node.js / SSR contexts, localStorage is undefined, causing a TypeError that crashes the render.

Changes

Wrap the module-level localStorage access in a typeof localStorage !== "undefined" guard, consistent with how other files in the codebase handle SSR (e.g., safeStorage.js, storageUtils.js).

Impact

  • SSR crash: Any page that imports timeSync.js during server-side rendering will throw TypeError: localStorage is not defined, breaking the build.
  • Affects functions setServerClockOffsetMs and the module initialization block that reads the cached offset.

Please assign this task to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    gssoc:approvedApproved for GSSoC contributionlevel:beginnerSmall, low-risk change (≤3 files, ≤50 lines)type:bugSomething is broken or incorrect

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions