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

fix(core): add URL polyfill for signer in react native #11362

Merged
merged 6 commits into from
May 11, 2023

Conversation

AllanZhengYP
Copy link
Member

@AllanZhengYP AllanZhengYP commented May 11, 2023

Description of changes

Manual integration test on the signer refactor indicates the URL polyfill is required for React Native. This change adds the ReactNative URL polyfill. Additional change to notifications unit test is required to fix a tranform issue.

Issue #, if available

React Native sample throws error in current main:

Error: URL.host is not implemented

Description of how you validated changes

This change has been released under the NPM tagged release fix-rn-signer-url, and manually validated in all providers using signer class in RN CLI and Expo and web/SSR.

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@AllanZhengYP AllanZhengYP marked this pull request as ready for review May 11, 2023 16:55
@AllanZhengYP AllanZhengYP requested review from a team as code owners May 11, 2023 16:55
Copy link
Contributor

@elorzafe elorzafe left a comment

Choose a reason for hiding this comment

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

Can you add more details on the dependency we are adding? It would be an issue if this includes react-native as peer dependency

@@ -67,6 +67,7 @@
"@aws-sdk/credential-provider-cognito-identity": "3.6.1",
"@aws-sdk/types": "3.6.1",
"@aws-sdk/util-hex-encoding": "3.6.1",
"react-native-url-polyfill": "^1.3.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

How large is this? does it have react-native as peerDependency?

Copy link
Member Author

@AllanZhengYP AllanZhengYP May 11, 2023

Choose a reason for hiding this comment

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

This dependency does not affect the web bundle size. It does not introcuce much extra install size either because the core package already has react-native dependency:

"react-native": "^0.64.1"

But front-end user might install react-native dependency. But it's not additional either, the AWS SDK client from the core brings in the react-native already:

└─┬ @aws-amplify/core@5.2.0
  └─┬ @aws-sdk/client-cloudwatch-logs@3.6.1
    └─┬ @aws-sdk/middleware-retry@3.6.1
      └─┬ react-native-get-random-values@1.8.0
        └── react-native@0.71.6

Copy link
Member Author

Choose a reason for hiding this comment

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

The react-native dependency is also deduped, so no extra install side either.

amplify-storage-ts@0.1.0 /Users/zheallan/workspace/tmp/amplify-storage-ts
├─┬ @aws-amplify/core@5.2.0
│ └─┬ @aws-sdk/client-cloudwatch-logs@3.6.1
│   └─┬ @aws-sdk/middleware-retry@3.6.1
│     └─┬ react-native-get-random-values@1.8.0
│       └── react-native@0.71.6 deduped
└─┬ aws-amplify@5.2.1-fix-rn-signer-url.dbacebc.7
  └─┬ @aws-amplify/core@5.2.1-fix-rn-signer-url.dbacebc.7
    └─┬ react-native-url-polyfill@1.3.0
      └── react-native@0.71.6

@AllanZhengYP AllanZhengYP requested review from elorzafe May 11, 2023 18:27
Copy link
Member

@cshfang cshfang left a comment

Choose a reason for hiding this comment

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

This is a fair approach imo. It's a quick change to revisit for V6 as well.

@@ -10,6 +10,11 @@ jest.mock('react-native', () => ({
removeEventListener: jest.fn(),
},
}));
jest.mock('react-native-url-polyfill', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Oh duh. Good solve

@@ -16,4 +16,9 @@ module.exports = {
functions: 95,
},
},
// Fix react native url polyfill transform issue of import statement.
// See: https://thymikee.github.io/jest-preset-angular/docs/11.0/guides/troubleshooting/#unexpected-token-importexportother
transformIgnorePatterns: [
Copy link
Member

Choose a reason for hiding this comment

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

Oh hum this was still needed despite the mocking? Ah well good work either way figuring this out.

@AllanZhengYP AllanZhengYP merged commit 720ac60 into main May 11, 2023
david-mcafee pushed a commit that referenced this pull request May 15, 2023
* fix(core): add RN url polyfill for signer code path

* test(notification): unblock unit test failure of rn url polyfill
@HuiSF HuiSF deleted the fix/rn-signer-url branch September 27, 2024 16:23
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.

5 participants