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

Fix issue with HMR and register the same predicate-less component again #5832

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions packages/registry/news/5832.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix issue with HMR and register the same predicate-less component again @sneridagh
5 changes: 4 additions & 1 deletion packages/registry/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,10 @@ class Config {
const hasRegisteredNoPredicatesComponent = this._data.slots?.[
slot
]?.data?.[name]?.find(({ predicates }) => !predicates);
if (hasRegisteredNoPredicatesComponent) {
if (
hasRegisteredNoPredicatesComponent &&
component !== hasRegisteredNoPredicatesComponent.component
) {
throw new Error(
`There is already registered a component ${name} for the slot ${slot}. You can only register one slot component with no predicates per slot.`,
);
Expand Down
17 changes: 17 additions & 0 deletions packages/registry/src/registry.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -733,4 +733,21 @@ describe('Slots registry', () => {
config.unRegisterSlotComponent('toolbar', 'save', 1);
expect(config.getSlotComponent('toolbar', 'save').length).toEqual(1);
});

// The next one fixes the issue when HMR kicks in and tries to register the same component again
it('registerSlotComponent - registers the same named slot component twice, does not break', () => {
const TestComponent = () => <div>Hello</div>;

config.registerSlotComponent({
slot: 'toolbar',
name: 'save',
component: TestComponent,
});

config.registerSlotComponent({
slot: 'toolbar',
name: 'save',
component: TestComponent,
});
});
});
Loading