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

Avoid config redux state overwrite #432

Merged
merged 1 commit into from
Sep 8, 2022
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
2 changes: 2 additions & 0 deletions packages/gasket-plugin-config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# `@gasket/plugin-config`

- Avoid potential overwriting of custom config state

### 6.20.4

- More descriptive error handling for hooks that do not return results ([#359])
Expand Down
5 changes: 4 additions & 1 deletion packages/gasket-plugin-config/lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ module.exports = {
const { redux } = req.config || {};
return {
...state,
config: redux
config: {
...state.config,
...redux
}
};
},
metadata(gasket, meta) {
Expand Down
17 changes: 17 additions & 0 deletions packages/gasket-plugin-config/test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,5 +232,22 @@ describe('Plugin', () => {
config: { something: 'public' }
});
});

it('does not overwrite any previously-prevent config state', async () => {
delete req.config;
const startingState = {
config: { some: { custom: 'config' } }
};

const newState = await plugin.hooks.initReduxState(
gasket,
startingState,
req,
res);

expect(newState).toEqual({
config: { some: { custom: 'config' } }
});
});
});
});