@enonic/nextjs-adapter 1.0.2 → 2.0.0-B2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,12 +4,12 @@ export interface StaticContentProps extends Record<string, any> {
4
4
  element?: string;
5
5
  condition: boolean;
6
6
  }
7
- export default function StaticContent({ children, element, condition, ...props }: StaticContentProps): import("react").DOMElement<{
8
- [x: string]: any;
9
- }, Element> | import("react").ReactElement<{
10
- ref: boolean | import("react").MutableRefObject<any>;
7
+ export default function StaticContent({ children, element, condition, ...props }: StaticContentProps): import("react").ReactElement<{
8
+ ref: import("react").RefObject<unknown>;
11
9
  suppressHydrationWarning: boolean;
12
10
  dangerouslySetInnerHTML: {
13
11
  __html: string;
14
12
  };
15
- }, string | import("react").JSXElementConstructor<any>>;
13
+ }, string | import("react").JSXElementConstructor<any>> | import("react").DOMElement<{
14
+ [x: string]: any;
15
+ }, Element>;
@@ -9,30 +9,28 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
- import { createElement, useEffect, useRef, useState } from 'react';
13
- function useStaticContent() {
14
- const ref = useRef(null);
15
- const [render, setRender] = useState(typeof window === 'undefined');
16
- useEffect(() => {
17
- var _a;
18
- // check if the innerHTML is empty as client side navigation
19
- // need to render the component without server-side backup
20
- const isEmpty = ((_a = ref === null || ref === void 0 ? void 0 : ref.current) === null || _a === void 0 ? void 0 : _a.innerHTML) === '';
21
- if (isEmpty) {
22
- setRender(true);
23
- }
24
- }, []);
25
- return [render, ref];
12
+ import { createElement, createRef } from 'react';
13
+ function useStaticContent(ref, isServer) {
14
+ var _a;
15
+ if (isServer) {
16
+ return false;
17
+ }
18
+ if (((_a = ref === null || ref === void 0 ? void 0 : ref.current) === null || _a === void 0 ? void 0 : _a.innerHTML) === '') {
19
+ return false;
20
+ }
21
+ return true;
26
22
  }
27
23
  export default function StaticContent(_a) {
28
24
  var { children, element = 'div', condition = true } = _a, props = __rest(_a, ["children", "element", "condition"]);
29
- const [render, ref] = useStaticContent();
25
+ const isServer = typeof window === 'undefined';
26
+ const ref = createRef();
27
+ const isStatic = useStaticContent(ref, isServer);
28
+ // avoid re-render on the client
29
+ if (isStatic && condition) {
30
+ return createElement(element, Object.assign(Object.assign({}, props), { ref, suppressHydrationWarning: true, dangerouslySetInnerHTML: { __html: '' } }));
31
+ }
30
32
  // just render if:
31
33
  // - condition is false
32
34
  // - we're in the server or a spa navigation
33
- if (render || !condition) {
34
- return createElement(element, props, ...[].concat(children));
35
- }
36
- // avoid re-render on the client
37
- return createElement(element, Object.assign(Object.assign({}, props), { ref, suppressHydrationWarning: true, dangerouslySetInnerHTML: { __html: '' } }));
35
+ return createElement(element, props, ...[].concat(children));
38
36
  }
package/views/Text.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  import { MetaData, TextData } from '../guillotine/getMetaData';
3
3
  type Props = {
4
4
  meta: MetaData;
5
5
  component: TextData;
6
6
  path: string;
7
7
  };
8
- declare const DefaultTextView: ({ component, meta, path }: Props) => JSX.Element;
8
+ declare const DefaultTextView: ({ component, meta, path }: Props) => React.JSX.Element;
9
9
  export default DefaultTextView;