cal.com icon indicating copy to clipboard operation
cal.com copied to clipboard

[CAL-4694] embed issue with react 18.2

Open PeerRich opened this issue 1 year ago • 20 comments

looks like there is some problem with the react code for pop via element click. (using next15 and react 18.2)
Code is in the comments below

image

image

CAL-4694

PeerRich avatar Nov 08 '24 19:11 PeerRich

/bounty 20

PeerRich avatar Nov 08 '24 19:11 PeerRich

💎 $20 bounty • Cal.com, Inc.

Steps to solve:

  1. Submit work: Create a pull request including /claim #17563 in the PR body to claim the bounty
  2. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to calcom/cal.com!

Add a bountyShare on socials

algora-pbc[bot] avatar Nov 08 '24 19:11 algora-pbc[bot]

/attempt #17563

Algora profile Completed bounties Tech Active attempts Options
@itsalam 1 cal bounty
TypeScript, JavaScript,
Python
Cancel attempt

itsalam avatar Nov 08 '24 19:11 itsalam

***EDIT: Found it, Seems to exist specifically with next.

@PeerRich Could you provide some more reproduction steps? I've created an inline HTML at packages/embeds/embed-react:

<html>
  <head>
    <script src="https://unpkg.com/[email protected]/umd/react.development.js" crossorigin></script>
    <script src="https://unpkg.com/[email protected]/umd/react-dom.development.js" crossorigin></script>
    <script type="module" src="./test.tsx"></script>
  </head>
  <body>
    <div id="root"></div>
  </body>
</html>

As well as copied your file and adjusted to render to the html:

test.tsx:

import { useEffect } from "react";
import * as React from "react";
import ReactDom from "react-dom";

import { getCalApi } from "./dist/Cal.es.mjs";

function App() {
 useEffect(() => {
   (async function () {
     const cal = await getCalApi({
       namespace: "project-call",
     });
     cal("ui", {
       styles: { branding: { brandColor: "#000000" } },
       hideEventTypeDetails: false,
       layout: "month_view",
     });
   })();
 }, []);
 return (
   <button data-cal-namespace="project-call" data-cal-link="pro" data-cal-config='{"layout":"month_view"}'>
     Click me
   </button>
 );
}

ReactDom.render(<App />, document.getElementById("root"));

And it seems to run just fine on my end.

itsalam avatar Nov 08 '24 20:11 itsalam

/attempt #17563

Options

AdityaGupta-cyber avatar Nov 09 '24 00:11 AdityaGupta-cyber

Hey @PeerRich based on your description about the issue and the shared code, I've managed to come up with this solution 👇.

'use client';

import { getCalApi } from "@calcom/embed-react";
import { useEffect } from "react";

export default function MyApp() {
    useEffect(() => {
        (async () => {
            const cal = await getCalApi({
                namespace: "project-call",
            });
            if (cal) {
                cal("ui", {
                    styles: { branding: { brandColor: "#000000" } },
                    hideEventTypeDetails: false,
                    layout: "month_view",
                });
            }
        })();
    }, []);

    return (
        <button 
            data-cal-namespace="project-call" 
            data-cal-link="shaahid/project-call" 
            data-cal-config='{"layout":"month_view"}'
        >
            Click me
        </button>
    );
}

AdityaGupta-cyber avatar Nov 09 '24 00:11 AdityaGupta-cyber

Hey, @PeerRich , please let me know if the issue was not solved. I'll try to reimplement the solution.

Thanks!

AdityaGupta-cyber avatar Nov 09 '24 01:11 AdityaGupta-cyber

After going through the imports, it seems that Next 15 doesn't seem to be properly downgrading to React 18, even when specified in the package manager. This can be checked by logging the React package, which should contain its version.

image

The issue shown is a bug where mismatching react versions are being referenced: https://stackoverflow.com/questions/66194269/typeerror-cannot-read-propertyreactcurrentdispatcherof-undefined

There isn't much discussion, or a straightforward way to properly downgrade to React 18 on Next 15. While this could be remedied by either:

  • upgrading the react dependecies to react 19, or
  • to downgrade to Next 14, which properly works with React 18.

Which kinda sucks since either option is much more of a headache than whats bargained for.

itsalam avatar Nov 09 '24 04:11 itsalam

/attempt #17563

Options

Harsh9485 avatar Nov 09 '24 10:11 Harsh9485

/attempt #17563

Options

vishalpatil1899 avatar Nov 10 '24 14:11 vishalpatil1899

/attempt #17563

Options

vijay0984567 avatar Nov 11 '24 05:11 vijay0984567

Found this test in nextjs, which tests that it uses their own provided canary/experimental build for React: https://github.com/vercel/next.js/blob/676a3bad83a948e76454ac37faa4db2420d57b57/test/e2e/app-dir/rsc-basic/rsc-basic.test.ts#L529.

Seems that for now, any stable version of React 18 + Next 15 will not be compatible.

itsalam avatar Nov 12 '24 21:11 itsalam

export default function CalEmbed() {
    const HTML = `<!-- Cal inline embed code begins -->
        <div style="width:100%;height:100%;overflow:scroll" id="my-cal-inline"></div>
            <script type="text/javascript">
                (function (C, A, L) { let p = function (a, ar) { a.q.push(ar); }; let d = C.document; C.Cal = C.Cal || function () { let cal = 
                C.Cal; let ar = arguments; if (!cal.loaded) { cal.ns = {}; cal.q = cal.q || []; 
                d.head.appendChild(d.createElement("script")).src = A; cal.loaded = true; } if (ar[0] === L) { const api = function () 
                { p(api, arguments); }; const namespace = ar[1]; api.q = api.q || []; if(typeof namespace === "string") 
                {cal.ns[namespace] = cal.ns[namespace] || api;p(cal.ns[namespace], ar);p(cal, ["initNamespace", namespace]);} 
                else p(cal, ar); return;} p(cal, ar); }; })(window, "https://app.cal.com/embed/embed.js", "init");
                Cal("init", "15min", {origin:"https://cal.com"});

                Cal.ns["15min"]("inline", {
                  elementOrSelector:"#my-cal-inline",
                  config: {"layout":"month_view"},
                  calLink: "username/15min",
                });

               Cal.ns["15min"]("ui", {"styles":{"branding": 
               {"brandColor":"#000000"}},"hideEventTypeDetails":false,"layout":"month_view"});
          </script>

     <!-- Cal inline embed code ends -->`

    // biome-ignore lint/security/noDangerouslySetInnerHtml: <explanation>
    return <div dangerouslySetInnerHTML={{ __html: HTML }} />
} 

This is working in the interim for anyone building on Next.js 15 that needs to embed Cal. Just replace the HTML const with your HTML code from Cal.

doug-andrade avatar Nov 25 '24 16:11 doug-andrade

/attempt #17563

Options

sujal12344 avatar Dec 19 '24 04:12 sujal12344

For me #17790 did fix this, can you verify? so upgrading react-embed to 1.5.2 may work cc @Praashh

KlotzJesse avatar Dec 21 '24 17:12 KlotzJesse

? What happened here... ?

35C4n0r avatar Jan 16 '25 11:01 35C4n0r

Hey @keithwillcode @hariombalhara could you please check on if this bounty applies to that issue being solved by #17790, that fixed it for me, can you verify? so upgrading react-embed to 1.5.2 may work

KlotzJesse avatar Jan 16 '25 16:01 KlotzJesse

/attempt https://github.com/calcom/cal.com/issues/17563

CodeProcastinator avatar Feb 08 '25 15:02 CodeProcastinator

/attempt #17563

AyushGoyanka avatar Apr 12 '25 04:04 AyushGoyanka

/attempt https://github.com/calcom/cal.com/issues/17563

wildduck2 avatar May 05 '25 04:05 wildduck2

@PeerRich Issue(bounty) is still open ?

onkar717 avatar Jul 19 '25 16:07 onkar717

/attempt #17563

hihry avatar Aug 02 '25 17:08 hihry

Tested and it works now.

https://github.com/zhyd1997/cal-embed-react-demo/pull/1

https://github.com/user-attachments/assets/bc9041d6-01f3-4093-a512-a31edd7bdb4c

zhyd1997 avatar Aug 08 '25 06:08 zhyd1997

/attempt https://github.com/calcom/cal.com/issues/17563

anglerfishlyy avatar Aug 14 '25 09:08 anglerfishlyy

/attempt https://github.com/calcom/cal.com/issues/17563

saurabhraghuvanshii avatar Aug 27 '25 23:08 saurabhraghuvanshii

/attempt #17563

PrateekSingh070 avatar Aug 29 '25 16:08 PrateekSingh070

Hello everyone, can you please check if it works now or not?

anikdhabal avatar Aug 30 '25 17:08 anikdhabal

Hello everyone, can you please check if it works now or not?

I think it is fixed now. #23406

saurabhraghuvanshii avatar Aug 31 '25 09:08 saurabhraghuvanshii

Is it get fixed, or can i try??

guptaavinash09 avatar Sep 02 '25 08:09 guptaavinash09

It seems that the issue might be fixed now. Unless someone shares a recording that this is still an issue, I would prefer to close this issue soon.

hariombalhara avatar Sep 09 '25 11:09 hariombalhara