@pushwoosh/single-spa 0.2.3 → 0.2.5

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/Parcel.js CHANGED
@@ -1,12 +1,14 @@
1
1
  import React, { useMemo } from 'react';
2
2
  import { mountRootParcel } from 'single-spa';
3
3
  import SingleSpaParcel from 'single-spa-react/parcel';
4
+ import { useSPAContext } from '@pushwoosh/spa-context';
4
5
  export const Parcel = ({
5
6
  className,
6
7
  module,
7
8
  parcelFunctionName = 'parcel',
8
9
  ...transferProps
9
10
  }) => {
11
+ const spaContext = useSPAContext();
10
12
  const parcelConfig = useMemo(() => {
11
13
  let parcel;
12
14
  return {
@@ -32,6 +34,7 @@ export const Parcel = ({
32
34
  }, [module, parcelFunctionName]);
33
35
  return React.createElement(SingleSpaParcel, {
34
36
  ...transferProps,
37
+ spaContext: spaContext,
35
38
  config: parcelConfig,
36
39
  wrapClassName: className,
37
40
  mountParcel: mountRootParcel,
@@ -2,38 +2,58 @@ import React, { Component } from 'react';
2
2
  import ReactDOMClient from 'react-dom/client';
3
3
  import singleSpaReact from 'single-spa-react';
4
4
  import { SPAContextProvider } from '@pushwoosh/spa-context';
5
- class AppWrapper extends Component {
6
- constructor(props) {
7
- super(props);
8
- this.state = {
9
- hasError: false
10
- };
11
- }
12
- static getDerivedStateFromError() {
13
- return {
14
- hasError: true
15
- };
16
- }
17
- componentDidCatch(error, errorInfo) {
18
- console.error('AppWrapper caught an error', error, errorInfo);
19
- }
20
- render() {
21
- if (this.state.hasError) {
22
- return React.createElement("div", null, "Application has been crashed! Please try again later!");
5
+ export function createApplicationFunction(Comp) {
6
+ class AppWrapper extends Component {
7
+ constructor(props) {
8
+ super(props);
9
+ this.state = {
10
+ hasError: false
11
+ };
12
+ }
13
+ static getDerivedStateFromError() {
14
+ return {
15
+ hasError: true
16
+ };
17
+ }
18
+ componentDidCatch(error, errorInfo) {
19
+ console.error('AppWrapper caught an error', error, errorInfo);
20
+ }
21
+ render() {
22
+ if (this.state.hasError) {
23
+ return React.createElement("div", {
24
+ style: {
25
+ display: 'flex',
26
+ flexDirection: 'column',
27
+ alignItems: 'center',
28
+ justifyContent: 'center',
29
+ maxWidth: 520,
30
+ margin: '64px auto',
31
+ padding: 24,
32
+ textAlign: 'center'
33
+ }
34
+ }, React.createElement("h2", {
35
+ style: {
36
+ margin: '0 0 8px',
37
+ fontSize: 20,
38
+ fontWeight: 500
39
+ }
40
+ }, "Something went wrong"), React.createElement("p", {
41
+ style: {
42
+ margin: 0,
43
+ color: '#7C8595'
44
+ }
45
+ }, "Please refresh the page or try again later."));
46
+ }
47
+ return React.createElement(SPAContextProvider, {
48
+ value: this.props.spaContext
49
+ }, React.createElement(Comp, {
50
+ ...this.props
51
+ }));
23
52
  }
24
- return React.createElement(SPAContextProvider, {
25
- value: this.props.spaContext
26
- }, this.props.children);
27
53
  }
28
- }
29
- export function createApplicationFunction(Comp) {
30
54
  return singleSpaReact({
31
55
  React,
32
56
  ReactDOMClient,
33
- rootComponent: props => React.createElement(AppWrapper, {
34
- spaContext: props.spaContext
35
- }, React.createElement(Comp, {
36
- ...props
37
- }))
57
+ rootComponent: AppWrapper
38
58
  });
39
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/single-spa",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "React component for build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",