Skip to content

Commit

Permalink
fix: ensure StreamContext is a singltone
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Dec 7, 2023
1 parent 6272686 commit b2172d7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/server/useStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ export { StreamProvider }
export type { StreamUtils }

import React, { useContext } from 'react'
import { assert } from './utils'
import { assert, getGlobalObject } from './utils'

type StreamUtils = {
injectToStream: (htmlChunk: string) => void
}
const StreamContext = React.createContext<StreamUtils | null>(null)

const globalObject = getGlobalObject('useStream.ts', {
StreamContext: React.createContext<StreamUtils | null>(null)
})
const { StreamContext } = globalObject
const StreamProvider = StreamContext.Provider

function useStream(): StreamUtils | null {
Expand Down
1 change: 1 addition & 0 deletions src/server/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from '../utils/assert'
export * from '../utils/debug'
export * from '../utils/isPromise'
export * from '../utils/isBrowser'
export * from '../utils/getGlobalObject'

0 comments on commit b2172d7

Please sign in to comment.