Skip to content

Commit 76b99f8

Browse files
committed
fix(nextjs): clean up config parsing matches and remove lint comment
1 parent 6c0aa37 commit 76b99f8

3 files changed

Lines changed: 40 additions & 3 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
"@arkenv/nextjs": patch
3+
---
4+
5+
#### Add non-wrapping setup API, dynamic client environment variables, and refactor parser integration
6+
7+
Improve the Next.js integration with the following enhancements:
8+
9+
- **Non-wrapping Setup API**: Expose `setupArkEnv` from `@arkenv/nextjs/config` and a side-effect import `@arkenv/nextjs/register` to allow setting up ArkEnv in `next.config.js` without wrapping the configuration.
10+
- **Dynamic Client Environment Variables**: Implement `<ArkEnvScript />` component that runs during SSR to inject `NEXT_PUBLIC_*` environment variables dynamically into the browser (`globalThis.__arkenv_env__`), allowing containerized deployments to swap public variables at runtime without rebuilds.
11+
- **Code Deduplication**: Refactor `@arkenv/nextjs/config` to import shared watcher, layout resolution, and key extraction helpers from `@arkenv/build`.
12+
13+
Usage:
14+
15+
```ts
16+
// next.config.js
17+
import "@arkenv/nextjs/register";
18+
19+
export default {
20+
// your normal next config
21+
};
22+
```
23+
24+
```tsx
25+
// app/layout.tsx
26+
import { ArkEnvScript } from "@arkenv/nextjs";
27+
28+
export default function RootLayout({ children }) {
29+
return (
30+
<html>
31+
<head>
32+
<ArkEnvScript />
33+
</head>
34+
<body>{children}</body>
35+
</html>
36+
);
37+
}
38+
```

packages/nextjs/src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@ export function extractKeys(content: string): {
378378
const arrayContent = sharedMatch[1];
379379
const stringRegex =
380380
/(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|`([^`\\]*(?:\\.[^`\\]*)*)`)/g;
381-
let match;
382-
while ((match = stringRegex.exec(arrayContent)) !== null) {
381+
const matches = arrayContent.matchAll(stringRegex);
382+
for (const match of matches) {
383383
const val = match[1] || match[2] || match[3];
384384
if (val) {
385385
optionSharedKeys.push(val);

packages/nextjs/src/script.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export function ArkEnvScript({
3939
return (
4040
<script
4141
id="arkenv-script"
42-
// biome-ignore lint/security/noDangerouslySetInnerHTML: needed to inject the env variables script tag
4342
dangerouslySetInnerHTML={{ __html: scriptContent }}
4443
/>
4544
);

0 commit comments

Comments
 (0)