Skip to content

address settings related hydration issues using prehydrate #1948

@liangmiQwQ

Description

@liangmiQwQ

Describe the bug

According to useSettings.ts, now all settings are stored in localStorage, it is a client only storage which means server side should never read the settings or it will just get default settings.

settingsRef = useLocalStorage<AppSettings>(STORAGE_KEY, DEFAULT_SETTINGS, {

However, there are some pages require settings like searchProvider and run it on server side, make users who has modified settings get hydration errors, page flashing and even worse cases.

Like if we set Data source to npm and access https://npmx.dev/~antfu will trigger page flashing and some unexpected behaviors

Image

Solution

A easy solution is make all components called useSettings to be client only, but it's essentially a workaround, I think a better solution is migrating all the settings to cookie (Would it be more reasonable to migrate everything there instead of only migrating necessary ones?)

Additional context

No response

Logs

inline
  10:27946  error  Redundant role "list" on <ul>  no-redundant-role
  10:31520  error  Redundant role "list" on <ul>  no-redundant-role
  10:43548  error  Redundant role "list" on <ul>  no-redundant-role
  10:47720  error  Redundant role "list" on <ul>  no-redundant-role
  10:52413  error  Redundant role "list" on <ul>  no-redundant-role
  10:59418  error  Redundant role "list" on <ul>  no-redundant-role
  10:63616  error  Redundant role "list" on <ul>  no-redundant-role
  10:68288  error  Redundant role "list" on <ul>  no-redundant-role
  10:71926  error  Redundant role "list" on <ul>  no-redundant-role
  10:75503  error  Redundant role "list" on <ul>  no-redundant-role
  10:79632  error  Redundant role "list" on <ul>  no-redundant-role
  10:83171  error  Redundant role "list" on <ul>  no-redundant-role

✖ 12 problems (12 errors, 0 warnings)

Metadata

Metadata

Assignees

No one assigned

    Labels

    frontFrontend, Designhelp wantedExtra attention is needed

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions