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

"URL" is not supported in RN #54

Closed
Ethella opened this issue Apr 17, 2020 · 0 comments
Closed

"URL" is not supported in RN #54

Ethella opened this issue Apr 17, 2020 · 0 comments
Assignees

Comments

@Ethella
Copy link
Member

Ethella commented Apr 17, 2020

@Ethella commented on Sat Feb 15 2020

https://github.com/facebook/react-native/blob/0.59-stable/Libraries/Blob/URL.js#L157

RN does not support URL, need to rewrite it in a different format


@Ethella commented on Wed Feb 19 2020

Two options,

  1. Adding hacks on global.js
    import { URL, URLSearchParams } from "whatwg-url";
    global.URL = URL;
    global.URLSearchParams = URLSearchParams;

This is will create overhead to developers

  1. Or rewrite new URL in SDK
    Losing tidiness on SDK, and reinvent the wheel of an existing package

Will come back to find best solution


@smithki commented on Fri Feb 21 2020

This can be worked around using NodeJS url module: facebook/react-native#16434

There is also a polyfill specifically for this: https://github.com/charpeni/react-native-url-polyfill


@Ethella commented on Mon Feb 24 2020

@smithki I agree, there is quite a lot of workaround.

But the decision is if we proceed with the solution of 2 in 1 bundle in fortmatic-js,

  • Is it small enough that we can just refactor to code that's platform-agnostic.
  • Or do we delegate this to the RN developer to add configuration their app?
    • For example, in the doc we write to use fortmatic-js please download react-native-url-polyfill and require ('react-native-url-polyfill')
    • There have been quite a lot of environment setup for RN to run formatic-js

Here's a copy of what I add to RN to make fortmatic-js work so far, some of them are not necessary. I'll prune them later.

if (typeof __dirname === 'undefined') global.__dirname = '/'
if (typeof __filename === 'undefined') global.__filename = ''
if (typeof process === 'undefined') {
    global.process = require('process')
} else {
    const bProcess = require('process')
    for (var p in bProcess) {
        if (!(p in process)) {
            process[p] = bProcess[p]
        }
    }
}
global.Buffer = require('buffer').Buffer
global.process = require('process')
global.process.env.NODE_ENV = __DEV__ ? 'development' : 'production'
if (typeof btoa === 'undefined') {
    global.btoa = function (str) {
        return new Buffer(str, 'binary').toString('base64')
    }
}
if (typeof atob === 'undefined') {
    global.atob = function (b64Encoded) {
        return new Buffer(b64Encoded, 'base64').toString('binary')
    }
}
process.browser = false
if (typeof Buffer === 'undefined') global.Buffer = require('buffer').Buffer
global.location = { protocol: 'file:' }
const isDev = typeof __DEV__ === 'boolean' && __DEV__
process.env['NODE_ENV'] = isDev ? 'development' : 'production'
if (typeof localStorage !== 'undefined') {
    localStorage.debug = isDev ? '*' : ''
}

import { URL, URLSearchParams } from "whatwg-url";
global.URL = URL;
global.URLSearchParams = URLSearchParams;

/* To inject window object for window.addEventListener */
if (global.window === undefined) {
    global.window = global;
}
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

No branches or pull requests

2 participants