Next.js Discord

Discord Forum

i am stuck on a bug from past 9-10days ,

Unanswered
Segugio Italiano posted this in #help-forum
Open in Discord
Segugio ItalianoOP
for example :

i am on page "/hotel/hote-pearl/rooms"

when i click on button it redirects to the new page " /hotel/hote-pearl/rooms/premium"

and when i click back button on the device and come to the page "/hotel/hote-pearl/rooms",
i get application error: a client-side exception has occurred (see the browser console for more information).

but when i refresh the page, it starts working perfectly.

15 Replies

Spectacled bear
@Segugio Italiano What is the error on console?
Segugio ItalianoOP
the props which are supposed to come from serversideprops are undefined
but when i refresh the page
it starts working fine
you'll need to show some code, we cannot guess from this much information
Segugio ItalianoOP
/hotel index.ts




export async function getServerSideProps(context: any) {
const { params, query, req, res } = await context;

const { checkin, checkout, num_nights, num_guests, num_children, num_rooms } =
hotelPageQueryHandler(query);

const hotel_slug = params?.hotelInfo;
let fetchHotelParams = new FetchHotelDetailsQueryParams();
fetchHotelParams.hotelSlugName = hotel_slug;
fetchHotelParams.numGuests = Number(num_guests);
fetchHotelParams.checkInDate = checkin;
fetchHotelParams.checkOutDate = checkout;
fetchHotelParams.fetchHotelAmenityList = true;
fetchHotelParams.fetchHotelFAQList = true;
fetchHotelParams.fetchHotelNearbyPlacesList = true;
fetchHotelParams.fetchHotelNearbyHotelsList = true;
fetchHotelParams.fetchHotelRoomsList = true;
fetchHotelParams.fetchAllHotelRoomsList = true;

const { hotelDetails } = await getHotelInformationDetails(fetchHotelParams);

const serializedHotelInfoDetails = JSON.stringify(hotelDetails);

return {
props: {
hotelInfoDetails: JSON.parse(serializedHotelInfoDetails),
checkin: String(checkin),
checkout: String(checkout),
num_nights: num_nights,
num_guests: num_guests,
num_rooms: num_rooms,
num_children: num_children,
},
};
}
/hotel/[roomId]


export async function getServerSideProps(context: any) {
const { params, query, req, res } = await context;

const { checkin, checkout, num_nights, num_guests, num_children, num_rooms } =
hotelPageQueryHandler(query);

const hotelSlugName = params?.hotelInfo;
const roomId = params?.roomId;

const hotelDetails: HotelInformationDetails =
await getHotelBookingPageDetails(hotelSlugName + "");
const roomDetails: HotelRoomInformation = await getHotelRoomPageDetails(
hotelSlugName,
roomId,
checkin,
checkout
);
const serializedHotelDetails = JSON.stringify(hotelDetails);
const serializedHotelRoomDetails = JSON.stringify(roomDetails);

return {
props: {
hotelDetails: JSON.parse(serializedHotelDetails),
roomDetails: JSON.parse(serializedHotelRoomDetails),
checkin: String(checkin),
checkout: String(checkout),
num_nights: num_nights,
num_guests: num_guests,
num_rooms: num_rooms,
num_children: num_children,
},
};
}
i am getting error in production,
its working fine in dev
even after building it
Segugio ItalianoOP
@joulev you'll need to show some code, we cannot guess from this much information
Segugio ItalianoOP
hey, thanks for your attention
@Spectacled bear <@851365807216132096> What is the error on console?
Segugio ItalianoOP
i have added screen recording of it
Segugio ItalianoOP
framework-0c7baedefba6b077.js:9 TypeError: Cannot read properties of undefined (reading 'hotel_Nearby_Places_List')
main-0737440c5e81cb22.js:1 A client-side exception has occurred, see here for more info: https://nextjs.org/docs/messages/client-side-exception-occurred