Skip to content

Progressive hydration strategy with context #2

@aralroca

Description

@aralroca

The progressive hydration strategy doesn't work well with react context, exactly in this scenario:

  1. Providing some context value on the top of the app.
  2. Consuming a context inside the children that is hydrated with the ProgressiveHydration component.
const Context = createContext()

function Content() {
  const value = useContext(Context)
  const [status, setStatus] = useState('not hydrated yet')

  useEffect(() => setStatus('hydrated'), [])

  return `status: ${status} - context value: ${value}`
}

function App() {
  return (
    <Context.Provider value="example">
      <ProgressiveHydration>
        <Content />
      </ProgressiveHydration>
    </Context.Provider>
  )
}

Result:

The context value is undefined after the rehydration...

Before hydration: status: not hydrated yet - context value: example
After hydration: status: hydrated - context value: undefined


I'm not sure if this can be solved in an easy way or there is some limitation on this strategy. Any idea @midudev ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions