Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@lingyan
Copy link
Member

@lingyan lingyan commented Nov 16, 2016

… render with empty href in prod with console error

Avoid crashing node process/ui thread in production just because one NavLink is configured wrong.

Will backport to 0.4.x after this PR is reviewed.

@kaesonho @mridgway @redonkulus

@yahoocla
Copy link

CLA is valid!

var navigateAction = require('../../../').navigateAction;
var RouteStore = require('../../../').RouteStore;
var ORIG_NODE_ENV = process.env.NODE_ENV;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OCD reorg

delete global.document;
delete global.navigator;
process.env.NODE_ENV = ORIG_NODE_ENV;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactor the logic in old beforeEach to be able to share between 3 test suites.

</MockAppComponent>
);
}).to['throw']();
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved out into 2 other test suites (one for dev env, the other for prod env) to test diff behaviors in diff environments.

var RouteStore = require('./RouteStore');
var debug = require('debug')('NavLink');
var navigateAction = require('./navigateAction');
var __DEV__ = process.env.NODE_ENV !== 'production';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have typically inlined this and used webpack to replace process.env.NODE_ENV.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha. Stole it from fluxible. Dont think it is inlined there.

webpack will replace here as well. And I thought we had concerns about accessing process.env.NODE_ENV on every invocation of a hot function (like NavLink render). Maybe that is no longer a concern?

@mridgway
Copy link
Collaborator

I've always been a fan of throwing for developer errors, but I'm don't feel strongly enough to reject this.

@lingyan
Copy link
Member Author

lingyan commented Nov 16, 2016

@mridgway I hear you. We had a production outage this morning because one of the link (out of many links) on the page failed to render. And it crashed the node processes. That is essentially what triggered this PR. We could ask NavLink users to validate href/routeName ahead of using NavLink. But a little hard to scale as every NavLink has to run the validation check :(

With this PR, we are still throwing in dev environment. (Granted, NODE_ENV dev environment is not the same as non-prod env in CI/CD pipeline :( ) Maybe I should figure out a way to do that instead. Throw in all non-prod CI/CD pipeline.

I'm open for better suggestions for sure.

} else {
var logError = (this.context.logger && this.context.logger.error) || console.error;
logError('Error: Invalid NavLink, skip rendering...', props);
return null;
Copy link
Contributor

@kaesonho kaesonho Nov 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of returning null, I'm thinking if we should just render empty href, and when user click, should return here https://github.com/yahoo/fluxible/blob/master/packages/fluxible-router/lib/createNavLinkComponent.js#L262 and fallback to native anchor behavior with empty href.

rendering null might break some visual experience if this happens unfortunately

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that. Updating. @kaesonho

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. @kaesonho Check it out :)

@kaesonho
Copy link
Contributor

👍

@lingyan
Copy link
Member Author

lingyan commented Nov 18, 2016

@mridgway @redonkulus more thoughts on this PR? I updated the PR to render with provided href prop in prod env (in the error case), instead of rendering null.

@redonkulus
Copy link
Collaborator

👍

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

Successfully merging this pull request may close these issues.

6 participants