Skip to content

React Native SupportΒ #91

@aaronholla

Description

@aaronholla

First off just wanted to say i love this package and how easy to understand the code is for something so complex. πŸ‘πŸ½

I was experimenting a bit with running capnweb inside a react-native app.

Surprisingly there was not very much that didn't work from what i could tell.

I did however come across a couple minor issues that i had to patch. Wanted to share those here in hopes that we can upstream something to allow running capnweb in react-native with no patches.

  1. Hermes (react-native's JS runtime) does not support Promise.withResolvers
  2. Metro gets tripped up on the dynamic import.

Promise.withResolvers

To fix the withResolvers issue I was able to fix this by adding a polyfill (Although a more robust polyfill may be needed for better memory management??, Not entirely sure as i didn't profile):

import { Platform } from 'react-native'

if (Platform.OS !== "web") {
  globalThis.Promise.withResolvers = function () {
    let resolve, reject;
    const promise = new Promise((res, rej) => {
      resolve = res;
      reject = rej;
    });
    return { resolve, reject, promise };
  };
}

Dynamic Imports

For the dynamic imports this PR seems to fix the bundling issues #82

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions