11import { CenterType , ResizeHandlePlacement , AnchorType , Type } from "../core-types" ;
2- import { useSpace , ParentContext , LayerContext , DOMRectContext , IReactSpaceInnerProps , useEffectOnce , SSR_SUPPORT_ENABLED } from "../core-react" ;
2+ import {
3+ useSpace ,
4+ ParentContext ,
5+ LayerContext ,
6+ DOMRectContext ,
7+ IReactSpaceInnerProps ,
8+ useEffectOnce ,
9+ SSR_SUPPORT_ENABLED ,
10+ useUniqueId ,
11+ } from "../core-react" ;
312import * as React from "react" ;
413import { Centered } from "./Centered" ;
514import { CenteredVertically } from "./CenteredVertically" ;
6- import { shortuuid , updateStyleDefinition } from "../core-utils" ;
15+ import { updateStyleDefinition } from "../core-utils" ;
716
817function applyCentering ( children : React . ReactNode , centerType : CenterType | undefined ) {
918 switch ( centerType ) {
@@ -22,8 +31,13 @@ export class Space extends React.Component<IReactSpaceInnerProps> {
2231}
2332
2433const SpaceInner : React . FC < IReactSpaceInnerProps & { wrapperInstance : Space } > = ( props ) => {
25- if ( ! props . id && ! props . wrapperInstance [ "_react_spaces_uniqueid" ] ) {
26- props . wrapperInstance [ "_react_spaces_uniqueid" ] = `s${ shortuuid ( ) } ` ;
34+ let idToUse = props . id ?? props . wrapperInstance [ "_react_spaces_uniqueid" ] ;
35+
36+ const uniqueId = useUniqueId ( ) ;
37+
38+ if ( ! idToUse ) {
39+ props . wrapperInstance [ "_react_spaces_uniqueid" ] = uniqueId ;
40+ idToUse = props . wrapperInstance [ "_react_spaces_uniqueid" ] ;
2741 }
2842
2943 const {
@@ -56,7 +70,7 @@ const SpaceInner: React.FC<IReactSpaceInnerProps & { wrapperInstance: Space }> =
5670
5771 const { space, domRect, elementRef, resizeHandles } = useSpace ( {
5872 ...props ,
59- ...{ id : props . id || props . wrapperInstance [ "_react_spaces_uniqueid" ] } ,
73+ ...{ id : idToUse } ,
6074 } ) ;
6175
6276 useEffectOnce ( ( ) => {
@@ -66,6 +80,12 @@ const SpaceInner: React.FC<IReactSpaceInnerProps & { wrapperInstance: Space }> =
6680 if ( space . element . getAttribute ( "data-ssr" ) === "1" ) {
6781 const preRenderedStyle = space . element . children [ 0 ] ;
6882 if ( preRenderedStyle ) {
83+ const id = preRenderedStyle . getAttribute ( "data-id" ) ;
84+ if ( id ) {
85+ space . id = id ;
86+ console . log ( space . id ) ;
87+ }
88+
6989 const newStyle = document . createElement ( "style" ) ;
7090 newStyle . id = `style_${ space . id } ` ;
7191 newStyle . innerHTML = preRenderedStyle . innerHTML ;
@@ -123,7 +143,11 @@ const SpaceInner: React.FC<IReactSpaceInnerProps & { wrapperInstance: Space }> =
123143 props . as || "div" ,
124144 outerProps ,
125145 < >
126- { SSR_SUPPORT_ENABLED && space . ssrStyle && < style className = "ssr" > { space . ssrStyle } </ style > }
146+ { SSR_SUPPORT_ENABLED && space . ssrStyle && (
147+ < style className = "ssr" data-id = { space . id } >
148+ { space . ssrStyle }
149+ </ style >
150+ ) }
127151 < div className = { innerClasses . join ( " " ) } style = { innerStyle } >
128152 < ParentContext . Provider value = { space . id } >
129153 < LayerContext . Provider value = { undefined } >
0 commit comments