New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calendar CSS not loading sometimes error on Next.js #7284
Comments
Looks like other people are experiencing the same issue I am using the same stack as the author of that stack overflow https://stackoverflow.com/questions/75920011/nextjs-fullcalendar-only-loading-partly-the-style |
You can just add <Script src="https://cdn.jsdelivr.net/npm/fullcalendar@6.1.5/index.global.min.js" /> Where import Script from 'next/script'; This is my full code implementation import { useEffect, useRef, useState } from 'react';
import { Calendar } from '@fullcalendar/core';
import dayGridPlugin from '@fullcalendar/daygrid';
import googleCalendarPlugin from '@fullcalendar/google-calendar';
import Script from 'next/script';
export default function MyCalendar() {
const calendarRef = useRef<HTMLDivElement>(null);
const [calendar, setCalendar] = useState<any>(null);
useEffect(() => {
if (calendarRef.current && !calendar) {
const newCalendar = new Calendar(calendarRef.current, {
plugins: [googleCalendarPlugin, dayGridPlugin],
googleCalendarApiKey: process.env.NEXT_PUBLIC_GOOGLE_API_KEY,
events: {
googleCalendarId: process.env.NEXT_PUBLIC_CALENDAR_ID,
},
});
newCalendar.render();
setCalendar(newCalendar);
}
}, [calendar, calendarRef]);
return (
<div ref={calendarRef}>
<Script src="https://cdn.jsdelivr.net/npm/fullcalendar@6.1.5/index.global.min.js" />
</div>
);
} |
Hey @hadhaz thanks for the feedback. I will give it a try to your solution, however, why are you not using the "@fullcalendar/react" library? Where you using it before? and then to fix the issue you moved to using the core one? |
I'm struggling to connect google calendar API with fullcalendar, fullcalendar documentation just provides how to connect without @fullcalendar/react I'm happy if you have a solution to connect google calendar api with @fullcalendar/react |
Sorry @hadhaz I am not using google calendar in my project |
@reymon359 Did you find a solution to this problem? I am facing the same issue |
hey @jocovass, not the best solution but it is working until some library maintainer answers with a proper solution. I created this component export const CalendarStyleSheets = () => (
<>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/fullcalendar@5.11.3/main.min.css" />
<style>{`.fc .fc-timeline-body{min-height:100%;position:relative;z-index:1}.fc .fc-timeline-slots{bottom:0;position:absolute;top:0;z-index:1}.fc .fc-timeline-slots>table{height:100%}.fc .fc-timeline-slot-minor{border-style:dotted}.fc .fc-timeline-slot-frame{align-items:center;display:flex;justify-content:center}.fc .fc-timeline-header-row-chrono .fc-timeline-slot-frame{justify-content:flex-start}.fc .fc-timeline-header-row:last-child .fc-timeline-slot-frame{overflow:hidden}.fc .fc-timeline-slot-cushion{padding:4px 5px;white-space:nowrap}.fc-direction-ltr .fc-timeline-slot{border-right:0!important}.fc-direction-rtl .fc-timeline-slot{border-left:0!important}.fc .fc-timeline-now-indicator-container{bottom:0;left:0;position:absolute;right:0;top:0;width:0;z-index:4}.fc .fc-timeline-now-indicator-arrow,.fc .fc-timeline-now-indicator-line{border-color:var(--fc-now-indicator-color);border-style:solid;position:absolute;top:0}.fc .fc-timeline-now-indicator-arrow{border-left-color:transparent;border-right-color:transparent;border-width:6px 5px 0;margin:0 -6px}.fc .fc-timeline-now-indicator-line{border-width:0 0 0 1px;bottom:0;margin:0 -1px}.fc .fc-timeline-events{position:relative;width:0;z-index:3}.fc .fc-timeline-event-harness,.fc .fc-timeline-more-link{position:absolute;top:0}.fc-timeline-event{z-index:1}.fc-timeline-event.fc-event-mirror{z-index:2}.fc-timeline-event{align-items:center;border-radius:0;display:flex;font-size:var(--fc-small-font-size);margin-bottom:1px;padding:2px 1px;position:relative}.fc-timeline-event .fc-event-main{flex-grow:1;flex-shrink:1;min-width:0}.fc-timeline-event .fc-event-time{font-weight:700}.fc-timeline-event .fc-event-time,.fc-timeline-event .fc-event-title{padding:0 2px;white-space:nowrap}.fc-direction-ltr .fc-timeline-event.fc-event-end,.fc-direction-ltr .fc-timeline-more-link{margin-right:1px}.fc-direction-rtl .fc-timeline-event.fc-event-end,.fc-direction-rtl .fc-timeline-more-link{margin-left:1px}.fc-timeline-overlap-disabled .fc-timeline-event{margin-bottom:0;padding-bottom:5px;padding-top:5px}.fc-timeline-event:not(.fc-event-end):after,.fc-timeline-event:not(.fc-event-start):before{border-color:transparent #000;border-style:solid;border-width:5px;content:"";flex-grow:0;flex-shrink:0;height:0;margin:0 1px;opacity:.5;width:0}.fc-direction-ltr .fc-timeline-event:not(.fc-event-start):before,.fc-direction-rtl .fc-timeline-event:not(.fc-event-end):after{border-left:0}.fc-direction-ltr .fc-timeline-event:not(.fc-event-end):after,.fc-direction-rtl .fc-timeline-event:not(.fc-event-start):before{border-right:0}.fc-timeline-more-link{background:var(--fc-more-link-bg-color);color:var(--fc-more-link-text-color);cursor:pointer;font-size:var(--fc-small-font-size);padding:1px}.fc-timeline-more-link-inner{display:inline-block;left:0;padding:2px;right:0}.fc .fc-timeline-bg{bottom:0;left:0;position:absolute;right:0;top:0;width:0;z-index:2}.fc .fc-timeline-bg .fc-non-business{z-index:1}.fc .fc-timeline-bg .fc-bg-event{z-index:2}.fc .fc-timeline-bg .fc-highlight{z-index:3}.fc .fc-timeline-bg-harness{bottom:0;position:absolute;top:0}`}</style>
<style>{`.fc .fc-resource-timeline-divider{cursor:col-resize;width:3px}.fc .fc-resource-group{font-weight:inherit;text-align:inherit}.fc .fc-resource-timeline .fc-resource-group:not([rowspan]){background:var(--fc-neutral-bg-color)}.fc .fc-timeline-lane-frame{position:relative}.fc .fc-timeline-overlap-enabled .fc-timeline-lane-frame .fc-timeline-events{box-sizing:content-box;padding-bottom:10px}.fc-timeline-body-expandrows td.fc-timeline-lane{position:relative}.fc-timeline-body-expandrows .fc-timeline-lane-frame{position:static}.fc-datagrid-cell-frame-liquid{height:100%}.fc-liquid-hack .fc-datagrid-cell-frame-liquid{bottom:0;height:auto;left:0;position:absolute;right:0;top:0}.fc .fc-datagrid-header .fc-datagrid-cell-frame{align-items:center;display:flex;justify-content:flex-start;position:relative}.fc .fc-datagrid-cell-resizer{bottom:0;cursor:col-resize;position:absolute;top:0;width:5px;z-index:1}.fc .fc-datagrid-cell-cushion{overflow:hidden;padding:8px;white-space:nowrap}.fc .fc-datagrid-expander{cursor:pointer;opacity:.65}.fc .fc-datagrid-expander .fc-icon{display:inline-block;width:1em}.fc .fc-datagrid-expander-placeholder{cursor:auto}.fc .fc-resource-timeline-flat .fc-datagrid-expander-placeholder{display:none}.fc-direction-ltr .fc-datagrid-cell-resizer{right:-3px}.fc-direction-rtl .fc-datagrid-cell-resizer{left:-3px}.fc-direction-ltr .fc-datagrid-expander{margin-right:3px}.fc-direction-rtl .fc-datagrid-expander{margin-left:3px}`}</style>
</>
) And then I load it in the page where the calendar is const NewBookingContent = () => {
return (
<FullCalendar
...
/>)
}
const NewBookingPage: NextPage = () => {
return (
<Layout title="New Booking">
<CalendarStyleSheets />
<NewBookingContent />
</Layout>
)
}
export default NewBookingPage Hope it helps! |
The only way it works for me if I preload the styles in <Head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/fullcalendar@5.11.3/main.min.css" />
</Head> |
I can confirm this works for me. I was facing broken fullcalender UI in production but adding stylesheet in _app.js fixed the issue. |
I'm appreciative of the workarounds, however, I really want to get this working without needing to import v5 static assets. Ideally the CSS the FullCalendar v6 injects would be applied, and stay applied, in all scenarios. I'm still in need of a reproduction. I've attempted to reproduce myself, but things work fine:
If someone could use the above examples as a starting point and post a recreation link (github repo or a codestandbox link), I'd be grateful. |
If the bug only appears in your production environment, can you please tell me which hosting provider you're using and any important instructions to get it working? If you think it's only production, can you attempt a static build on your machine first? |
I'm having the same issue on NextJS. It goes aways when I reload the page, when I think the css is resolved/loaded. This only happens on the first load. Seems to be an issue with NextJS since I think it deals with .css in a different way then other apps. I've been using Vercel to deploy @arshaw, but you should be able to reproduce locally if you open on a window in incognito mode and load the app for the first time. |
Hey @arshaw have you tried reproducing it using the timeline plugin? Also, to clarify, this does not happen in development mode. So in order to reproduce it, first build the project with next build + start it locally. You should see the styles not working. |
@vivianedias and @reymon359, please see this video of me attempting to recreate the bug. Please compare it to your own scenarios and lmk how I can go about successfully recreating it. https://www.loom.com/share/ce83e924b19c4f1fb0c72d10184e01d5 I'm using timeline view and using Github repo: https://github.com/fullcalendar/fullcalendar-examples/tree/main/next13 |
I created new next.js project and setup Fullcalendar in it. It was working fine on production. |
I was having issues on list view not having the proper styling only on Next.js production builds. I narrowed it down to some sort of conflict in my navbar component, specifically using Next's |
Thanks for the new info @nbenford Could everyone please tell me:
And of course, a runnable recreation would be invaluable. |
Hey @arshaw, sorry for the delay. I emailed hello@arshaw.com with my source code and answers to your questions. Let me know if you need anything else 😄 |
Hi @arshaw, I'm using Next 13.3.1 and I'm using the pages router. The odd thing is that I seemed to have fixed the issue the other day by altering the I'll get some runnable code to you as soon as I can. Thanks! |
This should be fixed in v6.1.8. Could all those who experienced the issue please upgrade and confirm that all is fixed? |
@arshaw I updated. The UI is fixed now on production. But after updating I am facing this error in production build when switching to month view. day and week views are working.
|
I'm having the same problem as @madelahsan. The update crashes my build. On the bright side, if I roll back to 6.1.7 and add
Into my calendar component, it renders fine. |
@madelahsan, I feel your problem might be unrelated. I cannot find anywhere in the current codebase where @nbenford, similar sentiment, I don't know things are breaking for you after the upgrade. I'd need a reduced test case to know why. Additionally, I don't know why including a global script tag would fix anything. |
Please post all issues (and accompanying reduced test cases) in separate tickets. Thanks! |
Reduced Test Case
STILL NEEDED
Do you understand that if a reduced test case is not provided, we will intentionally delay triaging of your ticket?
Which connector are you using (React/Angular/etc)?
React
Bug Description
Hey there 👋🏽
Sometimes, when the calendar loads, there are some issues with the CSS and the styles do not load properly:
Here is an example of how it loads
And now how it should load. This is how it loads most of the time:
I don't know why it happens. It happens from time to time, and reloading the window fixes it.
Do you know how to fix it forever?
Do you know what may be causing it?
Thanks a lot in advance!
Btw the reduced test case is the example one because I don't know how to reproduce it
The text was updated successfully, but these errors were encountered: