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

refactor: different config loading strategy #4807

Merged

Conversation

smashercosmo
Copy link
Contributor

@smashercosmo smashercosmo commented Jan 5, 2021

Summary

Fixes #4817

In this refactoring config loading has been moved from App.js to bootstrap.js, which makes App component "dumber". And also redundant mergeConfig and configDidLoad actions has been removed. This also should make #4776 merging easier.

Test plan

Run current tests

@smashercosmo smashercosmo requested a review from a team January 5, 2021 16:06
@erezrokah erezrokah added the type: chore work needed to keep the product and development running smoothly label Jan 5, 2021
@smashercosmo
Copy link
Contributor Author

Probably should add tests for loadConfig action

const configUrl = getConfigUrl();
const isPreloaded = preloadedConfig && preloadedConfig.size > 1;
const isPreloaded = preloadedConfig && Object.keys(preloadedConfig).length > 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be rather Object.keys(preloadedConfig).length > 0?

@smashercosmo
Copy link
Contributor Author

I believe this PR should also fix the problem with fast refresh. Currently when cms is being fast-refreshed, config validation results in error:

Unhandled Runtime Error
Error: 'collections[0].view_filters' should NOT have fewer than 1 items
'collections[0].view_groups' should NOT have fewer than 1 items

That's because after refresh, we validate existing config (which was normalized and to which defaults were applied), where each collection has view_filters and view_groups equal to empty array.

@erezrokah erezrokah force-pushed the different-config-loading-strategy branch from 6d4953c to 313c910 Compare January 13, 2021 16:37
Copy link
Contributor

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for this @smashercosmo, it's a tricky one, but the code looks much better now.

I added another commit with some cleanup and a fix to manual initialization.

Please let me know what you think.

@smashercosmo
Copy link
Contributor Author

thx @erezrokah. Much better with your changes.

@smashercosmo
Copy link
Contributor Author

btw, did you have a chance to check if this fixes the issue with hot reload?

@erezrokah
Copy link
Contributor

btw, did you have a chance to check if this fixes the issue with hot reload?

Yes it does 🥳

@erezrokah erezrokah enabled auto-merge (squash) January 13, 2021 17:51
@erezrokah erezrokah merged commit 77dd885 into decaporg:master Jan 13, 2021
vladdu pushed a commit to vladdu/netlify-cms that referenced this pull request Jan 26, 2021
* move config loading from App.js to bootstrap.js

* remove mergeConfig action

* introduce deepmerge package

* fix: manual init

Co-authored-by: erezrokah <erezrokah@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: chore work needed to keep the product and development running smoothly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

netlify-cms raises error after being hot-reloaded
2 participants