Skip to content

Commit 190a4a8

Browse files
authored
fix: Properly handle app layout suspended state (#3720)
1 parent b5eefb5 commit 190a4a8

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/app-layout/visual-refresh-toolbar/multi-layout.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ export function mergeProps(
9898
return Object.keys(toolbar).filter(key => key !== 'ariaLabels').length > 0 ? toolbar : null;
9999
}
100100

101-
export function useMultiAppLayout(props: SharedProps, isEnabled: boolean) {
101+
export function useMultiAppLayout(
102+
props: SharedProps,
103+
isEnabled: boolean
104+
): { registered: boolean; toolbarProps: ToolbarProps | null } {
102105
const [registration, setRegistration] = useState<RegistrationState<SharedProps> | null>(null);
103106
const { forceDeduplicationType } = props;
104107
const isToolbar = useAppLayoutFlagEnabled();
@@ -111,9 +114,13 @@ export function useMultiAppLayout(props: SharedProps, isEnabled: boolean) {
111114
setRegistration({ type: 'primary', discoveredProps: [] });
112115
return;
113116
}
114-
return awsuiPluginsInternal.appLayoutWidget.register(forceDeduplicationType, props =>
117+
const unregister = awsuiPluginsInternal.appLayoutWidget.register(forceDeduplicationType, props =>
115118
setRegistration(props as RegistrationState<SharedProps>)
116119
);
120+
return () => {
121+
unregister();
122+
setRegistration({ type: 'suspended' });
123+
};
117124
}, [forceDeduplicationType, isEnabled, isToolbar]);
118125

119126
useLayoutEffect(() => {
@@ -124,7 +131,7 @@ export function useMultiAppLayout(props: SharedProps, isEnabled: boolean) {
124131

125132
if (!isToolbar) {
126133
return {
127-
registered: 'primary',
134+
registered: true,
128135
// mergeProps is needed here because the toolbar's behavior depends on reconciliation logic
129136
// in this function. For example, navigation trigger visibility
130137
toolbarProps: mergeProps(props, []),

src/internal/plugins/controllers/app-layout-widget.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ interface SecondaryRegistration<Props> {
1212
update: (props: Props) => void;
1313
}
1414

15-
export type RegistrationState<Props> = PrimaryRegistration<Props> | SecondaryRegistration<Props>;
15+
interface SuspendedRegistration {
16+
type: 'suspended';
17+
}
18+
19+
export type RegistrationState<Props> =
20+
| PrimaryRegistration<Props>
21+
| SecondaryRegistration<Props>
22+
| SuspendedRegistration;
1623
type RegistrationType = RegistrationState<unknown>['type'];
1724

1825
type RegistrationChangeHandler<Props> = (

0 commit comments

Comments
 (0)