865bd57357
* Allow clicks inside dialog panel when target is inside shadow root * Introduce resettable “server” state This will aid in testing * Add SSR and hydration tests for react * Fix server rendering of Tabs on React 17 * Fix CS * Skip hydration tests * Tweak SSR implementation in Vue * Update changelog
40 lines
651 B
TypeScript
40 lines
651 B
TypeScript
type RenderEnv = 'client' | 'server'
|
|
|
|
class Env {
|
|
current: RenderEnv = this.detect()
|
|
currentId = 0
|
|
|
|
set(env: RenderEnv): void {
|
|
if (this.current === env) return
|
|
|
|
this.currentId = 0
|
|
this.current = env
|
|
}
|
|
|
|
reset(): void {
|
|
this.set(this.detect())
|
|
}
|
|
|
|
nextId() {
|
|
return ++this.currentId
|
|
}
|
|
|
|
get isServer(): boolean {
|
|
return this.current === 'server'
|
|
}
|
|
|
|
get isClient(): boolean {
|
|
return this.current === 'client'
|
|
}
|
|
|
|
private detect(): RenderEnv {
|
|
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
return 'server'
|
|
}
|
|
|
|
return 'client'
|
|
}
|
|
}
|
|
|
|
export let env = new Env()
|