Skip to content
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

mdx-embed return empty components #220

Open
johackim opened this issue Mar 19, 2021 · 8 comments
Open

mdx-embed return empty components #220

johackim opened this issue Mar 19, 2021 · 8 comments
Assignees

Comments

@johackim
Copy link

johackim commented Mar 19, 2021

Describe the bug

I test mdx-embed with nodejs without browser, and It return an empty component.

To Reproduce

import React from 'react';
import { renderToString } from 'react-dom/server';
import { Tweet } from 'mdx-embed';

const result = renderToString(<Tweet tweetLink="PaulieScanlon/status/1232982448310497286" />);

console.log(result);

Expected behaviour

Have an iframe with a Tweet embedded

Actual behaviour

It return an empty component : <div data-testid="general-observer" class="mdx-embed"><div style="height:0;width:100%"></div></div>

Additional context

node version : v12.21.0

@PaulieScanlon
Copy link
Owner

Hey @johackim thanks for opening an issue. I haven't investigated @mdx-js/runtime could you share a little more info on how it might differ from @mdx-js/mdx

@johackim
Copy link
Author

Hello @PaulieScanlon ! Thanks for your response :)

I use @mdx-js/runtime directly with nodejs. I build a cli tool to convert markdowns with mdx components to html.

@johackim
Copy link
Author

johackim commented Mar 22, 2021

Hello @PaulieScanlon, here a codesandbox to demonstrate the problem : https://codesandbox.io/s/mdx-embed-99hnm

PS: I remove @mdx-js/runtime, in fact, it's not a part of the issue.

@johackim johackim changed the title mdx-embed with @mdx-js/runtime return empty component mdx-embed return empty component Mar 22, 2021
@johackim johackim changed the title mdx-embed return empty component mdx-embed return empty components Mar 22, 2021
@PaulieScanlon
Copy link
Owner

PaulieScanlon commented Mar 23, 2021

@johackim could it be related to this?

mdx-js/mdx#558

The other thing I've been thinking is that all MDX Embed components rely on the Intersection Observer. E.g when a component enters the viewports the child embed script is loaded. Intersection observer is a browser API so it might be that the components are being passed correctly but they won't load because the intersection observer never enters the viewport. Does that make sense?

@johackim
Copy link
Author

@PaulieScanlon,

Yes you're right, the isChildVisible is set to false by default and it is never set to true when used with nodejs (no browser).

@PaulieScanlon
Copy link
Owner

Thanks for the update. One thing we could do... and this will probably be part of the ongoing global config work is to allow some kind of config option to turn the intersection observer off. By default it should use intersection observers because this is what keeps MDX Embed "polite" but I guess there's no harm in turning this functionality off if required. I might be able to slip in a quick update that exposes an optional prop on a component that will do a similar thing.

Is there any single component you urgently need? Perhaps I could make a change to just the Tweet component and release an -alpha version for you to test with?

@johackim
Copy link
Author

johackim commented Apr 5, 2021

No, there is no urgent for a single component, a global config option to turn the observer off seems to be a good idea, I will wait for this update :)

Thanks @PaulieScanlon

@PaulieScanlon PaulieScanlon self-assigned this Jun 11, 2021
@PaulMest
Copy link

PaulMest commented Feb 2, 2023

I just ran into this problem one as well. I am using NextJS to update my blogs and migrate off of WordPress. Sometimes the embedded Tweets show up, others times they don't. It seems like the General Observer does not consistently fire. If I refresh the page, the Tweet always loads. However, if I navigate to a page a second time, the General Observer never loads. Though, I can trick it into loading again by scrolling down and then scrolling up.

Barring fixing the logic so that the General Observer always fires properly, I would definitely advocate for a "don't lazy load this embed option".

// simple example
<Tweet tweetLink="bernhardsson/status/1605357323643506695" lazyLoad={false} />

// or taking inspiration from the <Script> tag

// This seems to be the default now?
<Tweet tweetLink="bernhardsson/status/1605357323643506695" loadStrategy="lazyInViewport" /> 

// Some new options
<Tweet tweetLink="bernhardsson/status/1605357323643506695" loadStrategy="lazyOnload" />
<Tweet tweetLink="bernhardsson/status/1605357323643506695" loadStrategy="afterInteractive" />
<Tweet tweetLink="bernhardsson/status/1605357323643506695" loadStrategy="beforeInteractive" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants