#Json Import just getting cache or something and causing a serious problem

12 messages · Page 1 of 1 (latest)

frank grove
#

Hey, guys Im importing the json in astro like normal way, but when I manipulate the object of that json using Object.assign way it just got cache or something and not updating until I make some changes in the json file and hit save button,

#

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
frank grove
#

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 ???

frank grove
#

Anyone up support patrol??

marble bolt
last forge
#

I looked at this, it's a more vite related, so beyond my Astro knowledge, and might require a reproduction repo as the issue is hard to grasp, reproduce.

#

Not sure if vite imports are not constants or supposed to be altered.