@swype-org/react-sdk 0.2.174 → 0.2.186

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,6 +8,42 @@ Published versions on npm are released as part of the **production** deploy work
8
8
 
9
9
  Pin a specific version in your app (for example `"@swype-org/react-sdk": "0.1.x"`) instead of relying on floating `latest` in production.
10
10
 
11
+ ## Browser globals
12
+
13
+ The SDK automatically polyfills the `Buffer` global on import. The embedded
14
+ smart-wallet provider used by the one-tap setup and signing flows references
15
+ the Node `Buffer` global at runtime; without a polyfill, browser bundles fail
16
+ with `An internal error was received. Details: Buffer is not defined`.
17
+
18
+ The polyfill is a no-op if the host application already defines `Buffer`
19
+ (e.g. via its own `vite-plugin-node-polyfills` or manual assignment), so it
20
+ never overwrites a host-provided polyfill.
21
+
22
+ ### When the host needs its own polyfill
23
+
24
+ ES module hoisting means the SDK polyfill only runs when the SDK module
25
+ graph first loads. If the host application imports another Buffer-using
26
+ library (for example `@solana/kit`, `@solana/spl-token`, `bs58`, or
27
+ `tweetnacl`) **outside** of the SDK's import graph, that library's
28
+ top-level code can run before the SDK polyfill and crash with
29
+ `ReferenceError: Buffer is not defined`.
30
+
31
+ In that case the host must polyfill `Buffer` itself, before any other
32
+ import. The pattern is:
33
+
34
+ ```ts
35
+ // src/polyfills.ts
36
+ import { Buffer } from 'buffer';
37
+ if (typeof globalThis.Buffer === 'undefined') {
38
+ globalThis.Buffer = Buffer;
39
+ }
40
+
41
+ // src/main.tsx — must be the FIRST import
42
+ import './polyfills';
43
+ import React from 'react';
44
+ // ...
45
+ ```
46
+
11
47
  ## Local development
12
48
 
13
49
  To use the package from a git checkout without waiting for npm: