When merging configuration objects, always preserve existing values and follow clear precedence rules to avoid unintentionally overriding settings. Use spread operators carefully and ensure the merge logic is implemented at the appropriate layer (preferably in action/store layer rather than component level).
When merging configuration objects, always preserve existing values and follow clear precedence rules to avoid unintentionally overriding settings. Use spread operators carefully and ensure the merge logic is implemented at the appropriate layer (preferably in action/store layer rather than component level).
Key principles:
{}
that can override existing configurationsExamples:
❌ Problematic merging - overwrites existing footerAction:
appearance={{
...appearance,
elements: {
...appearance.elements,
footerAction: !enableClerkSignUp ? { display: 'none' } : {}, // Empty object overwrites existing
}
}}
✅ Proper conditional merging:
appearance={{
...appearance,
elements: {
...appearance.elements,
...((!enableClerkSignUp) && { footerAction: { display: 'none' } }),
}
}}
❌ Component-level merging:
onChange={(value) => {
updatePluginSettings(id, { [item.name]: value }); // Overwrites other settings
}}
✅ Store-level merging:
// In store action
updatePluginSettings: (id, updates) => {
set((state) => ({
pluginSettings: {
...state.pluginSettings,
[id]: { ...state.pluginSettings[id], ...updates }
}
}));
}
This approach ensures configuration integrity and prevents accidental loss of user preferences or system settings.
Enter the URL of a public GitHub repository