Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release: stark-module-1.5.1 #507

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: rerender module after props changed (#592)
  • Loading branch information
ClarkXia authored Jan 6, 2023
commit 16dae47dc4ec5baf0cc51aa1408f8ff5df809fb0
5 changes: 5 additions & 0 deletions packages/icestark-module/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.5.1

- [fix] rerender module when props changed
- [fix] get latest props after load module bundles

## 1.5.0

- [fix] exports all library exports. ([#469](https://github.com/ice-lab/icestark/pull/469))
Expand Down
14 changes: 8 additions & 6 deletions packages/icestark-module/src/MicroModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export default class MicroModule extends React.Component<any, State> {
}

componentDidUpdate(prevProps) {
if (!shallowCompare(prevProps.moduleInfo || {}, this.props.moduleInfo || {})) {
const { moduleInfo: preModuleInfo = {}, ...preRest } = prevProps;
const { moduleInfo: curModuleInfo = {}, ...curRest } = this.props;

if (!shallowCompare(preModuleInfo, curModuleInfo) || !shallowCompare(preRest, curRest)) {
this.mountModule();
}
}
Expand Down Expand Up @@ -79,9 +82,6 @@ export default class MicroModule extends React.Component<any, State> {
}

async mountModule() {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { sandbox, moduleInfo, wrapperClassName, wrapperStyle, loadingComponent, handleError, ...rest } = this.props;

if (!this.moduleInfo) {
console.error(`Can't find ${this.props.moduleName} module in modules config`);
return;
Expand All @@ -93,20 +93,22 @@ export default class MicroModule extends React.Component<any, State> {
this.setState({ loading: true });

try {
const { mount, component } = await loadModule(this.moduleInfo, sandbox);
const { mount, component } = await loadModule(this.moduleInfo, this.props.sandbox);
const lifecycleMount = mount;

!this.unmout && this.setState({ loading: false });
if (lifecycleMount && component) {
if (this.unmout) {
unmoutModule(this.moduleInfo, this.mountNode);
} else {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { sandbox, moduleInfo, wrapperClassName, wrapperStyle, loadingComponent, handleError, ...rest } = this.props;
lifecycleMount(component, this.mountNode, rest);
}
}
} catch (err) {
this.setState({ loading: false });
handleError(err);
this.props.handleError(err);
}
}
}
Expand Down