@sitecore-feaas/clientside 0.5.20-alpha.1 → 0.5.21

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.
package/src/cdn.ts CHANGED
@@ -45,7 +45,7 @@ export type FEAASCDNStylesheetSource = {
45
45
  export type FEAASCDNStylesheetProps = FEAASCDNStylesheetParams | FEAASCDNStylesheetSource | string
46
46
 
47
47
  export function parseComponentSource(source: string): FEAASCDNComponentParams {
48
- const match = source?.match(
48
+ const match = source.match(
49
49
  /^(?:(.*?)\/components)?\/?([^\/]+)\/([^\/]+)(?:\/([^\/]+)(?:\/(published|staged|saved|\d+)(?:\.html?)?)?)?$/
50
50
  )
51
51
  if (match) {
@@ -75,7 +75,7 @@ export function getStylesheetSource(props: FEAASCDNStylesheetParams) {
75
75
  }
76
76
 
77
77
  export function parseStylesheetSource(source: string): FEAASCDNStylesheetParams {
78
- const match = source?.match(/^(?:(.*?)\/styles\/)?([^\/]+)(?:\/(published|staged|saved|\d+)(?:.css)?)?$/)
78
+ const match = source.match(/^(?:(.*?)\/styles\/)?([^\/]+)(?:\/(published|staged|saved|\d+)(?:.css)?)?$/)
79
79
  if (match) {
80
80
  var [, cdn, library, revision] = match
81
81
  return { cdn, library, revision: revision as any }
@@ -93,11 +93,11 @@ export function getComponentURL(props: FEAASCDNComponentProps | string) {
93
93
  if (typeof props == 'string') {
94
94
  props = { src: props }
95
95
  }
96
- if ('src' in props && props.src) {
96
+ if ('src' in props) {
97
97
  props = {
98
98
  ...parseComponentSource(props.src)
99
99
  }
100
- } else props = { ...(props as FEAASCDNComponentParams) }
100
+ }
101
101
  return `${props.cdn || props.hostname || DEFAULT_CDN_URL}/components/${props.library}/${props.component}/${
102
102
  props.version || 'responsive'
103
103
  }/${props.revision || 'published'}.html`
@@ -114,7 +114,7 @@ export function getStylesheetURL(props: FEAASCDNStylesheetProps) {
114
114
  props = {
115
115
  ...parseStylesheetSource(props.src)
116
116
  }
117
- } else props = { ...(props as FEAASCDNComponentParams) }
117
+ }
118
118
  return `${props.cdn || props.hostname || DEFAULT_CDN_URL}/styles/${props.library}/${
119
119
  props.revision == 'staged' ? 'staged' : props.revision == 'saved' ? 'saved' : 'published'
120
120
  }.css`
@@ -284,7 +284,7 @@ export class FEAASComponent extends FEAASElement<FEAASComponentsProps, string> {
284
284
 
285
285
  type FetchKeyword = 'data' | 'template' | 'stylesheet'
286
286
 
287
- declare module 'react' {
287
+ declare global {
288
288
  namespace JSX {
289
289
  interface IntrinsicElements {
290
290
  'feaas-component': {
@@ -341,8 +341,12 @@ export class FEAASElement<Props = any, Payload = any> extends WebComponent {
341
341
  if (!ReactDOM) throw new Error(`${this.tagName}: ReactDOM is not present in payload`)
342
342
  if (this.getAttribute('hydrate') == 'false' && this.firstElementChild) return
343
343
  if (!this.refs.topReact && !this.forceUpdateReact) {
344
- this.reactRoot ||= ReactDOMClient.createRoot(this.getReactRootElement())
345
- this.reactRoot.render(this.getReactElement())
344
+ if (ReactDOMClient) {
345
+ this.reactRoot ||= ReactDOMClient.createRoot(this.getReactRootElement())
346
+ this.reactRoot.render(this.getReactElement())
347
+ } else {
348
+ ReactDOM.render(this.getReactElement(), this.getReactRootElement())
349
+ }
346
350
  } else if (this.forceUpdateReact && this.connected) {
347
351
  this.forceUpdateReact?.()
348
352
  } else {
@@ -1,11 +1,9 @@
1
1
  import type { ReactNode, ReactElement, JSXElementConstructor, PropsWithChildren } from 'react'
2
2
  import { FEAASElement } from './FEAASElement.js'
3
- import type ReactDOMClient from 'react-dom/client'
4
3
 
5
4
  export type ReactModules = {
6
5
  React: typeof React
7
6
  ReactDOM: typeof ReactDOM
8
- ReactDOMClient: typeof ReactDOMClient
9
7
  }
10
8
  export type ReactJSX = ReactNode | ReactElement<any, string | JSXElementConstructor<any>>
11
9
  export type FEAASReactRender<P> = {
@@ -18,11 +16,9 @@ export default class FEAASReactElement<P> extends FEAASElement<P, ReactModules>
18
16
  // @ts-ignore @webpack-ignore
19
17
  import('https://cdn.skypack.dev/react'),
20
18
  // @ts-ignore
21
- import('https://cdn.skypack.dev/react-dom'),
22
- // @ts-ignore
23
- import('https://cdn.skypack.dev/react-dom/client')
24
- ]).then(([React, ReactDOM, ReactDOMClient]) => {
25
- return { React, ReactDOM, ReactDOMClient }
19
+ import('https://cdn.skypack.dev/react-dom')
20
+ ]).then(([React, ReactDOM]) => {
21
+ return { React, ReactDOM }
26
22
  })
27
23
  }
28
24
 
@@ -21,12 +21,7 @@ export type FEAASExternalProps = { componentName: string; [key: string]: any }
21
21
 
22
22
  export default class FEAASExternal extends FEAASElement<FEAASExternalProps, ReactModules> {
23
23
  load() {
24
- return Promise.all([
25
- // @ts-ignore
26
- import('https://cdn.skypack.dev/react-dom/client')
27
- ]).then(([ReactDOMClient]) => {
28
- return { React, ReactDOM, ReactDOMClient }
29
- })
24
+ return Promise.resolve({ React, ReactDOM })
30
25
  }
31
26
 
32
27
  // observe all arttribute changes
@@ -1,7 +1,6 @@
1
- import { createRoot, hydrateRoot } from 'react-dom/client'
2
1
  import React, { useContext } from 'react'
3
- import { flushSync } from 'react-dom'
4
- import { describe, expect, it, beforeEach, vi, afterEach } from 'vitest'
2
+ import ReactDOM from 'react-dom'
3
+ import { describe, expect, it, beforeEach, vi } from 'vitest'
5
4
  import {
6
5
  Component,
7
6
  ExternalComponent,
@@ -9,7 +8,6 @@ import {
9
8
  registerComponent,
10
9
  setElementImplementation
11
10
  } from '../src/ui/react.js'
12
- import ReactDOMClient from 'react-dom/client'
13
11
 
14
12
  function Hello(props: { firstName: string; telephone: string }) {
15
13
  const context = useContext(DataContext)
@@ -69,24 +67,24 @@ const helloDataSchema = {
69
67
  export async function validate(react: any, html: string) {
70
68
  const div = document.createElement('div')
71
69
  document.body.appendChild(div)
72
- const root = createRoot(div)
73
- flushSync(() => root.render(react))
70
+ const root = ReactDOM.render(react, div)
74
71
  expect(div.innerHTML).toEqual(html)
75
72
 
76
73
  const div2 = document.createElement('div')
77
74
  document.body.appendChild(div2)
78
75
  div2.innerHTML = html
79
76
 
80
- flushSync(() => hydrateRoot(div2, react))
77
+ var onHydrate
78
+ const promise = new Promise((r) => {
79
+ onHydrate = r
80
+ })
81
+ ReactDOM.hydrate(react, div2, onHydrate)
82
+ await promise
81
83
  expect(div2.innerHTML).toEqual(html)
82
84
  }
83
85
 
84
86
  const DataContext = React.createContext('DEFAULT')
85
87
 
86
- vi.mock('https://cdn.skypack.dev/react-dom/client', () => {
87
- return ReactDOMClient
88
- })
89
-
90
88
  describe('React', () => {
91
89
  beforeEach(() => {
92
90
  document.open()
@@ -2,12 +2,6 @@ import { beforeEach, describe, expect, it } from 'vitest'
2
2
  import React from 'react'
3
3
  import * as Clientside from '../src/ui/react.js'
4
4
  import FEAASExternal from '../src/ui/FEAASExternal.js'
5
- import { vi } from 'vitest'
6
- import ReactDOMClient from 'react-dom/client'
7
-
8
- vi.mock('https://cdn.skypack.dev/react-dom/client', () => {
9
- return ReactDOMClient
10
- })
11
5
 
12
6
  describe('External', () => {
13
7
  function Hello(props: { firstName: string; telephone: string }) {
@@ -191,7 +191,7 @@ describe('React Server', () => {
191
191
  })
192
192
  function MyComponent() {
193
193
  const { test } = useContext(Context)
194
- return <h1>{`My Component: ${test}`}</h1>
194
+ return <h1>My Component: {test}</h1>
195
195
  }
196
196
  registerComponent(MyComponent, {
197
197
  name: 'test-server-external-context'
@@ -1,4 +1,4 @@
1
- /// <reference types="react" resolution-mode="require"/>
1
+ /// <reference types="react" />
2
2
  import type * as FEAASContextImports from '@sitecore-feaas/frontend/context';
3
3
  import { FEAASElement, OptionalExcept } from '../components/FEAASElement.js';
4
4
  import { ControlledPromise } from '../utils/promise.js';
@@ -53,7 +53,7 @@ export declare class FEAASContext extends FEAASElement<FEAASContextProps, typeof
53
53
  clientside: typeof FEAAS;
54
54
  onStatusChange: FEAASContextImports.SDKStatusCallback;
55
55
  whenSDKReady: ControlledPromise<FEAASContextImports.SDK>;
56
- getPortalRoot(): FEAASElement<any, any> | HTMLElement | ShadowRoot;
56
+ getPortalRoot(): HTMLElement | ShadowRoot | FEAASElement<any, any>;
57
57
  render({ children, library }: React.PropsWithChildren<FEAASContextProps>, { AppContext, Chakra: { Button, Tooltip }, React }: typeof this.payload): FEAASContextImports.React.JSX.Element;
58
58
  }
59
59
  declare global {
@@ -1,4 +1,4 @@
1
- /// <reference types="react" resolution-mode="require"/>
1
+ /// <reference types="react" />
2
2
  import type * as FEAASEditorImports from '@sitecore-feaas/frontend/editor';
3
3
  import { FEAASElement, OptionalExcept } from '../components/FEAASElement.js';
4
4
  import { FEAASLoader } from '../components/FEAASLoader.js';
@@ -1,4 +1,4 @@
1
- /// <reference types="react" resolution-mode="require"/>
1
+ /// <reference types="react" />
2
2
  import type * as FEAASPickerImports from '@sitecore-feaas/frontend/picker';
3
3
  import { FEAASElement } from '../components/FEAASElement.js';
4
4
  export declare function FEAASPickerProps(element: FEAASElement<any, any>): {
@@ -1,4 +1,3 @@
1
- /// <reference types="@types/react" />
2
1
  import * as BYOC from '@sitecore/byoc/react';
3
2
  import React from 'react';
4
3
  import { HTMLNode, renderHTMLContent } from '../dom/html.js';
@@ -1 +1 @@
1
- {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/ui/react.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,sBAAsB,CAAA;AAC5C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,QAAQ,EAAoB,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAE9E,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,mBAAmB,EAOpB,MAAM,YAAY,CAAA;AACnB,cAAc,gBAAgB,CAAA;AAC9B,OAAO,EAAE,QAAQ,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACvF,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,iBAAiB,EAAE,CAAA;AAG5B;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,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