Skip to content

Commit

Permalink
fix: improve support for OnchainKit in Next.js 14+ apps (#1771)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschlabach authored Jan 9, 2025
1 parent 77ab84d commit bb79e09
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ docs/.vitepress/dist

*storybook.log
storybook-static/

# Tarballs
*.tgz
17 changes: 17 additions & 0 deletions packemon.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@ const config = {
},
]);
},

// Adding support for React 18's "use client" directive
// Mostly used with Next.js apps
rollupOutput(config) {
config.plugins.push({
name: 'fix-use-client',
renderChunk(code) {
if (code.includes("'use client'")) {
// Remove the original directive and split into lines
const lines = code.replace("'use client';", '').split('\n');
// Filter out any empty lines and reconstruct
return `'use client';\n${lines.filter((line) => line.trim()).join('\n')}`;
}
return null; // Return null to keep the original code (https://rollupjs.org/plugin-development/#renderchunk)
},
});
},
};

export default config;
1 change: 1 addition & 0 deletions src/ui/react/identity/components/Address.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client';
import { useIdentityContext } from '@/core-react/identity/providers/IdentityProvider';
import type { AddressReact } from '@/core-react/identity/types';
import { getSlicedAddress } from '@/core/identity/utils/getSlicedAddress';
Expand Down
1 change: 1 addition & 0 deletions src/ui/react/identity/components/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client';
import { useAvatar } from '@/core-react/identity/hooks/useAvatar';
import { useName } from '@/core-react/identity/hooks/useName';
import { useIdentityContext } from '@/core-react/identity/providers/IdentityProvider';
Expand Down
1 change: 1 addition & 0 deletions src/ui/react/identity/components/Badge.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client';
import type { BadgeReact } from '../../../../core-react/identity/types';
import { badgeSvg } from '../../../../internal/svg/badgeSvg';
import { background, cn } from '../../../../styles/theme';
Expand Down
1 change: 1 addition & 0 deletions src/ui/react/identity/components/EthBalance.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client';
import { useIdentityContext } from '@/core-react/identity/providers/IdentityProvider';
import type { EthBalanceReact } from '@/core-react/identity/types';
import { getRoundedAmount } from '@/core/utils/getRoundedAmount';
Expand Down
1 change: 1 addition & 0 deletions src/ui/react/identity/components/Identity.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client';
import { IdentityProvider } from '@/core-react/identity/providers/IdentityProvider';
import type { IdentityReact } from '@/core-react/identity/types';
import { useOnchainKit } from '@/core-react/useOnchainKit';
Expand Down
1 change: 1 addition & 0 deletions src/ui/react/identity/components/IdentityCard.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client';
import type { Address, Chain } from 'viem';
import { Address as AddressComponent } from './Address';
import { Avatar } from './Avatar';
Expand Down
1 change: 1 addition & 0 deletions src/ui/react/identity/components/Name.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client';
import { useName } from '@/core-react/identity/hooks/useName';
import { useIdentityContext } from '@/core-react/identity/providers/IdentityProvider';
import type { NameReact } from '@/core-react/identity/types';
Expand Down
1 change: 1 addition & 0 deletions src/ui/react/identity/components/Socials.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client';
import type { Address, Chain } from 'viem';
import { useName } from '../../../../core-react/identity/hooks/useName';
import { useSocials } from '../../../../core-react/identity/hooks/useSocials';
Expand Down

0 comments on commit bb79e09

Please sign in to comment.