#Json Import just getting cache or something and causing a serious problem
12 messages · Page 1 of 1 (latest)
Check this code :
import headerConfig from "@/config/header_customization.json";
const currentPage = Astro.url.pathname;
type HeaderConfigProps = {
absolute: Boolean;
navbar_primary_theme: String;
headerBg: String | null;
navbarBtnColor: String;
};
let pageConfig: HeaderConfigProps = headerConfig["default"];
let specificPageConfig = headerConfig[currentPage as keyof typeof headerConfig];
console.log(pageConfig);
console.log(specificPageConfig);
if (specificPageConfig) {
Object.assign(pageConfig, specificPageConfig);
}
console.log(pageConfig);
---
<header
class=`main-header ${pageConfig.absolute && "position-absolute" } ${pageConfig.headerBg} w-100`
>
<nav
class=`navbar navbar-expand-xl ${pageConfig.navbar_primary_theme} sticky-header z-10`
>
<div
{
"default": {
"absolute": false,
"navbar_primary_theme": "navbar-dark",
"headerBg": "bg-dark",
"navbarBtnColor": "primary"
},
"/": {
"absolute": true,
"headerBg": null,
"navbarBtnColor": "primary"
},
"/home2": {
"navbar_primary_theme": "navbar-light",
"navbarBtnColor": "something else"
},
"/home3": {
"absolute": true,
"headerBg": null
}
}
When Im doing this way it just got cached and repeating the last updated value after I hit save on the actual json file , check the output:
instead of pulling the actual data all the time it just get the cached data or the last updated data or Idk what its doing
<@&1129102257422610512>
but When I update the code and try diff approach
import headerConfig from "@/config/header_customization.json";
const currentPage = Astro.url.pathname;
type HeaderConfigProps = {
absolute: Boolean;
navbar_primary_theme: String;
headerBg: String | null;
navbarBtnColor: String;
};
let defaultConfig = headerConfig["default"];
let specificPageConfig = headerConfig[currentPage as keyof typeof headerConfig];
const mergedConfig: HeaderConfigProps = {
...defaultConfig,
...specificPageConfig,
};
console.log(mergedConfig);
it just worked but still I have to made the change in json file and hit saved and then it start working , but not working by Object.assign method Why is it so and Why after I removed the Object.assign logic and implemented the new one and still I have to change the json and hit save to refresh the cache or something or see the changes work ???????
is it cache or what , if it is then why its working with spread method and not object.assign method ???
Anyone up support patrol??
Many people are on vacation right now! Don't worry if we do not answer quickly for now ^^