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

Duplicate Proxy Calls #77

Closed
melloware opened this issue Sep 22, 2022 · 11 comments
Closed

Duplicate Proxy Calls #77

melloware opened this issue Sep 22, 2022 · 11 comments
Labels
bug Something isn't working

Comments

@melloware
Copy link
Contributor

melloware commented Sep 22, 2022

Describe the bug

Using latest React SDK I see the Proxy be query two times constantly.

image

Steps to reproduce the bug

Just run React app with proxy and watch the F12 network traffic.

Expected behavior

Only 1 call every 15 seconds

Logs, error output, etc.

No response

Screenshots

No response

Additional context

const unleashInstance: IConfig = {
	url: process.env.REACT_APP_UNLEASH_SERVER!,
	clientKey: process.env.REACT_APP_UNLEASH_KEY!,
	refreshInterval: 15,
	appName: 'clm',
	environment: process.env.REACT_APP_UNLEASH_ENV!,
	disableMetrics: true
};

Unleash version

Latest

Subscription type

Open source

Hosting type

Self-hosted

SDK information (language and version)

"@unleash/proxy-client-react": "^3.3.0",

@melloware melloware added the bug Something isn't working label Sep 22, 2022
@sighphyre
Copy link
Member

Hmm, this looks odd, thanks for raising this one. I'll add this to our list of things to look into next week

@FredrikOseberg
Copy link
Contributor

@melloware Is this happening in development or production?

@melloware
Copy link
Contributor Author

i am in development mode right now.

@melloware
Copy link
Contributor Author

i wasn't sure if this was a problem with React SDK or the client Proxy SDK so I reported it in both.

@FredrikOseberg
Copy link
Contributor

i wasn't sure if this was a problem with React SDK or the client Proxy SDK so I reported it in both.

Thanks for the clarification! I think this is not a bug with this project, but actually how hot module reloading works according to this issue.

I will close this issue for now, feel free to re-open if you disagree.

Repository owner moved this from Todo to Done in Issues and PRs Sep 23, 2022
@melloware
Copy link
Contributor Author

What is interesting about this is it starts happening even if I load my app fresh so its not like I have done any hot reloads or anything?

Also it looks like the Hot Reload library is no longer needed as Fast Refresh is already included in Core React right? See: facebook/react#16604

@melloware
Copy link
Contributor Author

I actually think to be good citizen you should be calling STOP on unmount as well like this..

React.useEffect(() => {
    const shouldStartClient = startClient || !unleashClient;
    if (shouldStartClient) {
      client.current.start();
    }

    // stop unleash client on unmount
    return function cleanup() {
       client.current.stop();
    };
  }, []);

@FredrikOseberg
Copy link
Contributor

What is interesting about this is it starts happening even if I load my app fresh so its not like I have done any hot reloads or anything?

Also it looks like the Hot Reload library is no longer needed as Fast Refresh is already included in Core React right? See: facebook/react#16604

Are you using react in strict mode? See this issue

@FredrikOseberg
Copy link
Contributor

I actually think to be good citizen you should be calling STOP on unmount as well like this..

React.useEffect(() => {
    const shouldStartClient = startClient || !unleashClient;
    if (shouldStartClient) {
      client.current.start();
    }

    // stop unleash client on unmount
    return function cleanup() {
       client.current.stop();
    };
  }, []);

Good idea. Feel free to open a separate issue or contribute a PR if you'd like. Otherwise I'll try to get to it next week.

@melloware
Copy link
Contributor Author

Yep confirmed its REact 18 Strict Mode causing the issue!!!

So what happens is render gets called twice to make sure you are being a good citizen with your renders. I have fixed this in other projects where they were not handling the renders correctly.

Like this one I reported in use-between and he fixed it: betula/use-between#33

@melloware
Copy link
Contributor Author

OK i will submit a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants