Unable to clear cache in Next.js using RTK query

Currently, I am utilizing Next.js along with next-redux-wrapper and RTK Query. My application is performing external API requests on the server side. The implementation of the request looks like this:

CompaniesPage.getInitialProps = initialPagePropsWithCompanies;

// ---
import { createWrapper } from 'next-redux-wrapper';

const wrapper = createWrapper<ReturnType<typeof makeStore>>(makeStore);
export const initialPagePropsWithCompanies = wrapper.getInitialPageProps((store: AppStore) => async () => {
  store.dispatch(api.endpoints.getHomePage.initiate());
  await Promise.all(store.dispatch(api.util.getRunningQueriesThunk()));
  return { props: {} };
});

The issue at hand is that the response seems to be cached somewhere in Next.js. I'm unsure how to disable it or shorten its lifespan.

  1. I have the line export const revalidate = 5; on my page.
  2. I've also included cache: 'no-store' in the fetchBaseQuery configuration:
  baseQuery: fetchBaseQuery({
    baseUrl: `${process.env.NEXT_PUBLIC_PROTOCOL || 'https://'}${process.env.NEXT_PUBLIC_VERCEL_URL}/api`,
    headers: {
      'x-telegram-query': typeof window !== 'undefined' ? window.Telegram.WebApp.initData : '',
    },
    cache: 'no-store',
  }),
  1. Additionally, I attempted adding next: { revalidate: 5 } to the fetchBaseQuery configuration.

Unfortunately, none of these solutions seem to be working. I'm out of ideas. Does anyone have any suggestions?

Answer №1

Here is a way to achieve it. triggerReload

export const reloadDelay = 0;

const LandingPage = async () => {
  const { info } = await database.update(
    profileApi.endpoints.getUserInfo.initiate(
      { userId: 5 },
      {
        triggerReload: true,
      }
    )
  );
  return (
    <div></div>
  );
};

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Fixing the hydration error in Next 13 can be challenging, especially when it occurs outside of a Suspense boundary

Encountering an issue while working with Next.js 13: Error: Hydration failed because the initial UI does not match what was rendered on the server. Warning: Expected server HTML to contain a matching <div> in <html>. Every time I attempt to r ...

Having issues with the basic KnockoutJS binding not functioning as expected

There appears to be an issue with my KnockoutJS script that I'm struggling to pinpoint. Below is the snippet of HTML code: <h2>SendMessage</h2> <div class="form-group" id="messageSender"> <label>Select User Type</l ...

Creating a layout of <video> components in vue.js, complete with the ability to rearrange and resize them through drag and drop functionality

Despite trying numerous libraries and Vue.js plugins, I have yet to find one that meets all of my requirements. I am in need of creating a grid of video HTML elements that are draggable and resizable with a consistent aspect ratio of 16:9. Additionally, I ...

When using React, I encountered a JSON return error: Unexpected token, it was expecting a comma

I encountered a syntax error while working on my React return statement The error specifically states: Syntax error: Unexpected token, expected "," After removing the problematic code block: {data.nodes && data.nodes.map((node) => ( ...

When attempting to execute the "npm run start" command in a ReactJS environment, an error message appeared

'react-scripts' command is not being recognized as a valid internal or external command, able to use program or batch file. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [email protected] start: react-scripts start npm ERR! Ex ...

Converting JSON information into a mailto hyperlink

Can anyone help me figure out how to encode a mailto link properly with JSON data in the query parameters, ensuring that it works even if the JSON data contains spaces? Let's consider this basic example: var data = { "Test": "Property with spaces" ...

Concealing items in a loop using Javascript

I need assistance with this issue. I am trying to hide text by clicking on a link, but it doesn't seem to be working correctly. Even though I tried the following code, I can't figure out why it's not functioning as expected. Is there a diff ...

I'm having trouble removing an element from an array. The splice() method doesn't seem to be working properly

I start by creating an array like this: let myArray = []; Next, I add Number elements to the array: myArray.push(myNumber); When I call myArray.toString(), the array looks like this: 1,4,3,9 I have been attempting to remove certain elements using t ...

Effective management and structuring of ExpressJS routes

I recently made the switch from PHP to NodeJS and Express, and I must say, it has been quite a learning experience. Following online tutorials to build web apps with Express has been eye-opening. I decided to tackle a project using just JavaScript, but I ...

Is there a specific side effect that warrants creating a new Subscription?

Recently, I had a discussion on Stack Overflow regarding RxJS and the best approach for handling subscriptions in a reactive application. The debate was whether it's better to create a subscription for each specific side effect or minimize subscriptio ...

Adding a button input and deleting non-functional parent elements

Here is a simple append function using jQuery, and it's working perfectly. However, the issue arises when I try to append a button and remove the parent tr upon clicking. The problem lies in using remove parent, as it doesn't seem to work as exp ...

The d3.select function is failing to update the chart on the website

I am facing a challenge in updating data in a d3 chart with the click on an HTML object #id. After successfully coding it in jsfiddle, I encountered issues when implementing it on a web page. The scenario involves a simple leaflet map where the chart is d ...

Encountering a problem with GraphQL API fetching in Next.js: receiving the error message "React functionality 'useContext' is not supported in this environment."

Currently, I have developed a Next.js 14.2.3 application with a GraphQL API endpoint (which I replaced with localhost for StackOverflow). For data fetching, I am utilizing "@apollo/client": "^3.10.3" and "graphql": "^16.8.1". The product page path has been ...

I encountered the following error: Failed to parse due to the module '@babel/preset-react' being missing

Encountering a parsing error: Module '@babel/preset-react' cannot be found. Upon creating schema.js, tweetSchema.js, userSchema.js, issues arose with import, export, and export from all three files showing red lines. schema.js: import createSche ...

Having trouble resetting a checked checkbox label in Vuejs?

uncheck: function(checkedName) { this.checkedNames = this.checkedNames.filter(name => name !== checkedName); }, uncheckall: function(event) { this.checkedNames = []; }, checkedInput(event) { if (this.checkedNames.includes(event.targ ...

The JQuery datepicker fails to provide the date in the format mm/dd/yy

Recently, I attempted to transform a date into the dd/mm/yy format using JQuery datepicker. Unfortunately, my results displayed in the dd/mm/yyyy format instead. Here is the code snippet that I utilized: chkIn = $.datepicker.formatDate("dd/mm/yy", cinDate ...

What is the process for triggering data-dismiss after the href has been activated?

Could someone help me with this issue? <a class='btn btn-danger' href='page.html'>Delete</a> I am trying to activate the "data-dismiss" attribute after the "href" is activated. My initial attempt was using this code: < ...

Using JSP to send variables from an external Javascript file

After creating a timer function, I am looking to display the results on a different page. The setup involves a JSP file calling functions from a separate JS file in order to output the information to another screen: Instructions in the JSP file: <butt ...

Creating a Paytm payment link using API in a React Native app without the need for a server

Suppose a user enters all their details and the total cost of their order amounts to 15000 rupees. In that case, the app should generate a Paytm payment link for this amount and automatically open it in a web view for easy payment processing. Any suggesti ...

JavaScript allows you to set an expiration date for a specific item

I am facing an issue with a form that contains inputs. On clicking the submit button, I want to capture the current time and add 10 hours to it before updating the table cell named expdate. Although I have a function in place for this purpose, it seems to ...