question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Integrating to Salesforce LWC components

See original GitHub issue

Reduced Test Case

Hi, after digging some hours, I end up reporting the issue with not much investigation to share.

Integrating this lib (v5) to Salesforce LWC is not working for several reasons :

  1. The script tag version doesn’t want to load properly when imported in LWC framework because of Locker Service thing

    I found how to fix that by doing the following “patch” : Replace var FullCalendar = (function (exports) { by (function (exports) { window.FullCalendar = exports;

  2. The click handler is going crazy Clicking on any button trigger the “go to today” date change. I don’t understand why this happens.

    I tried to reproduce the issue using Lightning Out (the open source version of LWC) but it “unfortunately” works well : https://webcomponents.dev/edit/wZjyCV5g1kvGjA3j2CLo/src/app.js

    I can probably setup an example inside a Salesforce org that will show the issue, contact me in MP so that I can provide credentials for you. In the mean time we can consider this as “not reproducible with a link”.

Bug Description

  1. Upload fullcalendar zip as static resource (zip contains two root files, main.js & main.css)
  2. Setup a simple calendar component :

Template:

<template>
    <div
        data-id="calendar"
        lwc:dom="manual"
    ></div>
</template>

Controller:

import { LightningElement, wire } from 'lwc'

import fullCalendar from '@salesforce/resourceUrl/fullcalendar'

export default class TimeSlotCalendar extends LightningElement {
    calendar
    initialized = false

    async connectedCallback () {
        if (!this.initialized) {
            this.initialized = true

            try {
                await Promise.all([
                    loadScript(this, fullCalendar + '/main.js'),
                    loadStyle(this, fullCalendar + '/main.css')
                ])

                this.tryCalendarInitialization()
            } catch (error) {
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Error loading calendar',
                        message: JSON.stringify(error),
                        variant: 'error'
                    })
                )
            }
        }
    }

    tryCalendarInitialization () {
        const calendarElement = this.template.querySelector('[data-id=calendar]')

        // calendar.changeView('timeGridDay')
        this.calendar = new window.FullCalendar.Calendar(calendarElement, {
            locale: 'fr',
            headerToolbar: {
                left: 'today',
                center: 'prev,title,next',
                right: 'timeGridDay,timeGridWeek,dayGridMonth',
            },
            initialView: 'timeGridWeek',
            editable: false,
            dayMaxEvents: true,
            navLinks: true,
        })

        this.calendar.render()
    }
}

Meta file

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>51.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__HomePage</target>
    </targets>
</LightningComponentBundle>
  1. Drop the component to the home page
  2. Try to navigate in the calendar, not working, only going to “today” no matter what button you click

I will be more than happy to investigate further if I get more elements.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

1reaction
dan-flux-capacitycommented, Mar 19, 2021

@Bartheleway Sure, I’m using the latest version 5.5.1 because there are a handful of new features that are important for my project (such as sticky header), and just assigned FullCalendar to the window in the script file, at the end to allow for compatibility within LWC.

I’m setting the headerToolbar to not display, and created my own header in the LWC with buttons to call the available methods for Calendar navigation, etc. The trickier part is that I’m also using the Resource timeline views, so I had to essentially replace the expand/collapse function (hiding and showing child rows under a given resource) with a custom process, as I found this issue prevented the standard expand/collapse to just not respond to clicks. Basically hid the native FC icons that fire the show/hide on each row via the Resource Render Hooks, and replaced with custom buttons that called a custom function to find and show/hide associated child rows for the given Resource.

Event click functions appear to work fine, so those are used as normal.

Overall this is very functional, though performance can be issue with much larger data volumes (roughly when approaching about 5000 events), and I’m not sure how much of that is due to my hacks to make it work in LWC vs just general ability of the browser/javascript engine to render it all.

0reactions
johnpanoscommented, May 19, 2021

@Bartheleway Did that work?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Integrating External Data in Lightning Web Components
In this session, I will demonstrate the process of integrating a LWC with an external data source. We will explore the design phase...
Read more >
Integration in Lightning Web Components
How to implement Integration in Lightning Web Component using Apex Continuation.
Read more >
How to make Rest API callouts from Lightning Web ...
Hey folks! In this blog post, I will cover how we can make REST API callouts from Lightning Web Components.
Read more >
Salesforce and Youtube Integration | LWC | Lightning web ...
Salesforce and Youtube Integration · Now select the First result YouTube Data API V3 and now enable it on the next screen ·...
Read more >
How to invoke an LWC Component function from Aura ...
In this post, we will learn how to Invoke an LWC Component function from Aura Component when an event occurs in Aura.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found