@sitecore-feaas/clientside 0.5.20 → 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/dist/browser/headless.cjs.map +1 -1
- package/dist/browser/headless.esm.js.map +1 -1
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.esm.js.map +1 -1
- package/dist/browser/react.cjs.map +1 -1
- package/dist/browser/react.esm.js.map +1 -1
- package/dist/node/headless.cjs.map +1 -1
- package/dist/node/headless.esm.js.map +1 -1
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.esm.js.map +1 -1
- package/dist/node/react.cjs.map +1 -1
- package/dist/node/react.esm.js.map +1 -1
- package/headless.cjs.map +1 -1
- package/headless.js.map +1 -1
- package/package.json +5 -4
- package/react.cjs.map +1 -1
- package/react.js.map +1 -1
- package/src/cdn.ts +5 -5
- package/src/components/FEAASComponent.tsx +1 -1
- package/src/components/FEAASElement.tsx +6 -2
- package/src/components/FEAASReactElement.tsx +3 -7
- package/src/ui/FEAASExternal.tsx +1 -6
- package/test/FEAASComponent.react.test.tsx +9 -11
- package/test/FEAASExternal.test.tsx +0 -6
- package/test/ServerComponent.test.tsx +1 -1
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
|
|
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
|
|
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
|
|
96
|
+
if ('src' in props) {
|
|
97
97
|
props = {
|
|
98
98
|
...parseComponentSource(props.src)
|
|
99
99
|
}
|
|
100
|
-
}
|
|
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
|
-
}
|
|
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
|
|
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
|
-
|
|
345
|
-
|
|
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
|
-
|
|
23
|
-
|
|
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
|
|
package/src/ui/FEAASExternal.tsx
CHANGED
|
@@ -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.
|
|
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
|
|
4
|
-
import { describe, expect, it, beforeEach, vi
|
|
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 =
|
|
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
|
-
|
|
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>
|
|
194
|
+
return <h1>My Component: {test}</h1>
|
|
195
195
|
}
|
|
196
196
|
registerComponent(MyComponent, {
|
|
197
197
|
name: 'test-server-external-context'
|