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

Using via import / require() #24

Open
MikeRomaa opened this issue Jan 16, 2022 · 3 comments
Open

Using via import / require() #24

MikeRomaa opened this issue Jan 16, 2022 · 3 comments

Comments

@MikeRomaa
Copy link

It would be really convenient if the connection to the tracker can be initiated via an npm package import instead of a script tag (similarly to how react-devtools does it).

I'm trying to optimize a program running in an iframe and this would be perfect for that.

import 'react-render-tracker';
import React from 'react';
...
@MikeRomaa MikeRomaa changed the title enable tracker via npm package [Feature] enable tracker via npm package Jan 16, 2022
@fnpen
Copy link

fnpen commented Feb 3, 2022

Solution:

Rename index entry file to bootstrap and put it to new index file:

if (process.env.NODE_ENV === 'production') {
  require('./bootstrap');
} else {
  (() => {
    const script = document.createElement('script');
    script.type = 'text/javascript';
    script.defer = false;
    script.src = 'https://cdn.jsdelivr.net/npm/react-render-tracker';
    script.onload = () => require('./bootstrap');

    document.head.appendChild(script);
  })();
}

It will be loaded before the 'react-dom' module, it's a temporary, but working solution to use it without access to HTML markup.

@lahmatiy
Copy link
Owner

lahmatiy commented Aug 17, 2022

I consider that's a required functionality in some cases. It can't be polyfilled in some cases / scenarios, e.g. for React Native support (#11). I'm going to add such a functionality. I can't say ETA for sure, but maybe in next 1-2 months.

@lahmatiy
Copy link
Owner

For a clarification, it's not about NPM availability (it's available) but about issues related to using (injecting) with require / import.

@lahmatiy lahmatiy changed the title [Feature] enable tracker via npm package Using via import / require() Aug 17, 2022
@lahmatiy lahmatiy mentioned this issue Aug 17, 2022
62 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants