Zend certified PHP/Magento developer

Magento 2.4.2: In the checkout, the shipping cost doesn’t change on user switching the country and entering the zipcode

I got a custom shipping module which I am trying to use to compute shipping costs for both US and Canada. In the module, I am calling FedEx Carrier class method to get shipping rates to Canada. The problem is that switching country from US to Canada or vice versa and then leaving the field after entering the zipcode doesn’t change the shipping cost relevant for the changed country in the checkout page. Reloading the page will then show the relevant shipping cost. How to fix this?

<?php

namespace PerfectmakeupmirrorsCustomShippingModelCarrier;

use MagentoQuoteModelQuoteAddressRateRequest;
use MagentoShippingModelCarrierAbstractCarrier;
use MagentoShippingModelCarrierCarrierInterface;
use PerfectmakeupmirrorsPmmFedexModelCarrier;

/**
 * Custom shipping model
 */
class Customshipping extends AbstractCarrier implements CarrierInterface
{
    const SHIPPING_STANDARD = 'STD';
    const SHIPPING_2ND_DAY = '2DY';
    const SHIPPING_OVERNIGHT = 'ON';
    protected $_shipping_mode_strings = array(
        self::SHIPPING_STANDARD => 'Standard Ground',
        self::SHIPPING_2ND_DAY => 'Second Day',
        self::SHIPPING_OVERNIGHT => 'Next Day Air',
    );

    /**
     * @var string
     */
    protected $_code = 'customshipping';

    /**
     * @var bool
     */
    protected $_isFixed = true;

    /**
     * @var MagentoShippingModelRateResultFactory
     */
    private $rateResultFactory;

    /**
     * @var MagentoQuoteModelQuoteAddressRateResultMethodFactory
     */
    private $rateMethodFactory;

    /**
     * @var PerfectmakeupmirrorsCustomShippingHelperData
     */
    private $helper;

    /**
     * @var PsrLogLoggerInterface
     */
    protected $_logger;

    private $carrierFedex;

    /**
     * @param MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
     * @param MagentoQuoteModelQuoteAddressRateResultErrorFactory $rateErrorFactory
     * @param PsrLogLoggerInterface $logger
     * @param MagentoShippingModelRateResultFactory $rateResultFactory
     * @param MagentoQuoteModelQuoteAddressRateResultMethodFactory $rateMethodFactory
     * @param array $data
     */
    public function __construct(
        MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
        MagentoQuoteModelQuoteAddressRateResultErrorFactory $rateErrorFactory,
        PsrLogLoggerInterface $logger,
        MagentoShippingModelRateResultFactory $rateResultFactory,
        MagentoQuoteModelQuoteAddressRateResultMethodFactory $rateMethodFactory,
        PerfectmakeupmirrorsCustomShippingHelperData $helper,
        PerfectmakeupmirrorsPmmFedexModelCarrier $carrierFedex,
        array $data = []
    ) {
        parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);

        $this->rateResultFactory = $rateResultFactory;
        $this->rateMethodFactory = $rateMethodFactory;
        $this->carrierFedex = $carrierFedex;
        $this->_logger = $logger;
        $this->helper = $helper;
    }

    /**
     * Custom Shipping Rates Collector
     *
     * @param RateRequest $request
     * @return MagentoShippingModelRateResult|bool
     */
    public function collectRates(RateRequest $request)
    {
        if (!$this->getConfigFlag('active')) {
            return false;
        }

        
        $this->_logger->info("Start of Custom Shipping collectRates");
        if ($request->getDestCountryId() == "CA") {
            $this->_logger->info("Country ID: " . $request->getDestCountryId());
            $fedex_rate = $this->carrierFedex->collectRates($request);
            //$this->_logger->info("Fedex Rate " . $fedex_rate);
            return $fedex_rate;
        }

        /** @var MagentoShippingModelRateResult $result */
        $result = $this->rateResultFactory->create();

        /** @var MagentoQuoteModelQuoteAddressRateResultMethod $method */
        $method = $this->rateMethodFactory->create();

        $method->setCarrier($this->_code);
        $method->setCarrierTitle($this->getConfigData('title'));

        $method->setMethod($this->_code);
        $method->setMethodTitle($this->getConfigData('name'));

        $this->_logger->info(__FILE__ . ': At Start');

        // Get all the items.
        // NOTE: This getAllItems here is related to Quote and not the order.
        if ((!($items = $request->getAllItems())) or (count($items) == 0)) {
            return FALSE;
        }

//        $objectManager = MagentoFrameworkAppObjectManager::getInstance();
//        $attributeSet = $objectManager->create('MagentoEavApiAttributeSetRepositoryInterface');
//        $attributeSetRepository = $attributeSet->get(9);
//        $attribute_set_name = $attributeSetRepository->getAttributeSetName();
//        $this->_logger->info(__FILE__ . ": Attribute Set Name = $attribute_set_name");

        //Standard code commented. Custom code added.
        //$shippingCost = (float)$this->getConfigData('shipping_cost');
        $shippingCost = (float)$this->helper->compute_standard_shipping_cost($items);

        $method->setPrice($shippingCost);
        $method->setCost($shippingCost);

        $result->append($method);

        return $result;
    }

    /**
     * @return array
     */
    public function getAllowedMethods()
    {
        return [$this->_code => $this->getConfigData('name')];
    }
}