Code Monkey home page Code Monkey logo

Comments (8)

pomber avatar pomber commented on May 9, 2024 1

Awesome, that fixed the iframe flickering, thanks!

For other cases, maybe you can hide the handle, delayRender, and continueRender details inside one hook:

function useResumer() {
  const [handle] = useState(() => delayRender());

  const resumeRender = useCallback(() => {
    continueRender(handle);
  }, [handle]);

  return resumeRender;
}

or something like that.

from remotion.

pomber avatar pomber commented on May 9, 2024

Maybe iframes have a similar problem? They consistently disappear in some frames. Here's an example.

from remotion.

JonnyBurger avatar JonnyBurger commented on May 9, 2024

Good point! Let's also make an IFrame component then.

Can you try if this <IFrame> component solves your problem?

import {useCallback, useState} from 'react';
import {continueRender, delayRender} from 'remotion';

export const IFrame: React.FC<Omit<
	React.DetailedHTMLProps<
		React.IframeHTMLAttributes<HTMLIFrameElement>,
		HTMLIFrameElement
	>,
	'onLoad'
>> = (props) => {
	const [handle] = useState(() => delayRender());

	const onLoad = useCallback(() => {
		continueRender(handle);
	}, [handle]);

	return <iframe {...props} onLoad={onLoad} />;
};

I'll then add it to Remotion Core, add documentation and improve DX by adding an ESLint Rule to the Remotion plugin!

from remotion.

jeetiss avatar jeetiss commented on May 9, 2024

Hey @JonnyBurger awesome project!

I think that suspense can help with this issue!

We can create custom suspense catcher and delayRender inside, like this

import {continueRender, delayRender} from 'remotion';

class VideoSuspense extends Component {
  constructor () {
    this.state = {
      loading: false
    }
  }
  
  componentDidCatch(promise) {
    if (isPromise(promise)) {
      this.setState({ loading: true })
      delayRender()
      promise.then(() => {
        this.setState({ loading: true })
        continueRender()
      })

    } else {
      throw promise
    }
  }

  render () {
    return this.state.loading ? null : this.props.children
  }
}



// root

<VideoSuspense>
  <Video/>
</VideoSuspense>

it should be better, because we don't need to wrap components that already support suspense with remotion delayRender/continueRender, and can use existed ones

what do you think about that? I can help with implementation

from remotion.

JonnyBurger avatar JonnyBurger commented on May 9, 2024

@jeetiss If that is possible using Suspense, then that's definitely preferrable!

But how does it work? Where does that promise come from? How do we hook into the onLoad function of img, iframe component?

from remotion.

JonnyBurger avatar JonnyBurger commented on May 9, 2024

Since a lot of people are affected, I am going ahead with the original plan and will merge #32. There is now also an ESLint rule enabled which will warn you if you use the native or <iframe> component!

from remotion.

JonnyBurger avatar JonnyBurger commented on May 9, 2024

Fixed by #32

from remotion.

jeetiss avatar jeetiss commented on May 9, 2024

@JonnyBurger, yes ofc! i am going to open new issue for suspense

But how does it work?

I'm not the best explainer) super simple scheme:

  • Component loads some resource and throws a promise
  • ErrorBoundary catch this promise and wait until it resolves and continue render

Where does that promise come from?

Components throw them:

iframe component?

Iframe component is not so trivial for suspense, but can be implemented with hacks:
https://gist.github.com/threepointone/e73a87f7bbbebc78cf71744469ec5a15

Suspense is still experimental, but react community have a lot components that supports this feature
So i think it fit great for remotion

from remotion.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.