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

Use data resources to store react assets #25

Closed
wants to merge 14 commits into from

Conversation

realityforge
Copy link
Member

No description provided.

@realityforge
Copy link
Member Author

This was an attempt to get assets included as resources and them loading them in app like

  public void onModuleLoad()
  {
    final HTMLScriptElement script = (HTMLScriptElement) DomGlobal.document.createElement( "script" );
    script.type = "text/javascript";
    script.src = Resources.INSTANCE.reactDev().getSafeUri().asString();
    script.onload = e -> {
      loadReactDom();
      return null;
    };
    DomGlobal.document.body.appendChild( script );
  }

  private void loadReactDom()
  {
    final HTMLScriptElement script = (HTMLScriptElement) DomGlobal.document.createElement( "script" );
    script.type = "text/javascript";
    script.src = DomResources.INSTANCE.reactDomDev().getSafeUri().asString();
    script.onload = e -> {
      startApp();
      return null;
    };
    DomGlobal.document.body.appendChild( script );
  }

  private void startApp()
  {
  ...

The problem with this is that any react app will define classes that extend native types and these classes are defined prior to onModuleLoad() being invoked. They would then error because React.Component is undefined.


The only solution that seemed to work either involved writing a custom linker that loaded the react js before app is defined or better yet writing a linker that generated the host html. Both seemed more work than was currently justified at this stage with the imminent move to j2CL on the cards.

@realityforge realityforge deleted the UseDataResourcesToStoreReactAssets branch April 29, 2019 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant