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

only include isomorphic-fetch if the application has explicitly disabled native fetch #838

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
* @typedef {import("./typings/metrics").TickingMetric} TickingMetric
*/

require('isomorphic-fetch');
// only include isomorphic-fetch if the application has explicitly disabled native fetch
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: could we expand this comment to add a bit of context on why we're doing this? afaict it's to satisfy problem hub as there won't be any behavioural change (as isomorphic-fetch already checks if native fetch is present)

Copy link
Member Author

@apaleslimghost apaleslimghost Jul 31, 2024

Choose a reason for hiding this comment

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

so this idea is from Jen's original native fetch investigation. which i should have read a bit closer, because the reason she's suggesting doing it this way is so we can add a warning here. i'll do that. maybe?

if (
process.allowedNodeEnvironmentFlags.has('--no-experimental-fetch') &&
process.execArgv.includes('--no-experimental-fetch')
Comment on lines +11 to +12
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: not that we support said versions anymore, but process.allowedNodeEnvironmentFlags.has('--no-experimental-fetch') resolving to false implies that this is an older Node version without support for native fetch so we should fallback to isomorphic-fetch in that case

Suggested change
process.allowedNodeEnvironmentFlags.has('--no-experimental-fetch') &&
process.execArgv.includes('--no-experimental-fetch')
!process.allowedNodeEnvironmentFlags.has('--no-experimental-fetch') ||
process.execArgv.includes('--no-experimental-fetch')

Copy link
Member Author

Choose a reason for hiding this comment

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

oh very good point

) {
require('isomorphic-fetch');
}

const fs = require('fs');
const path = require('path');
Expand Down Expand Up @@ -68,7 +74,8 @@ const getAppContainer = (options) => {
if (options.withAb) {
logger.warn({
event: 'WITHAB_OPTION_DEPRECATED',
message: 'The \'withAb\' option is deprecated and no longer supported by n-express or n-flags-client'
message:
"The 'withAb' option is deprecated and no longer supported by n-express or n-flags-client"
Comment on lines +77 to +78
Copy link
Member

Choose a reason for hiding this comment

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

This looks like prettier or something edited an unrelated bit of code. The config seems wrong because ESLint is complaining about double quotes.

Copy link
Contributor

Choose a reason for hiding this comment

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

bike shedding territory:

});
}

Expand Down