@wular/pnext 0.0.18 → 0.0.19

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/config.ts +21 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wular/pnext",
3
- "version": "0.0.18",
3
+ "version": "0.0.19",
4
4
  "description": "A fast little framework for server-first React apps, fully compatible with Next.js",
5
5
  "type": "module",
6
6
  "bin": {
package/src/config.ts CHANGED
@@ -193,18 +193,27 @@ export function pathToFileHref(filePath: string) {
193
193
  }
194
194
 
195
195
  export function publicEnvDefines() {
196
- return Object.fromEntries(
197
- [
198
- // eslint-disable-next-line turbo/no-undeclared-env-vars
199
- ['NODE_ENV', process.env.NODE_ENV ?? 'production'],
200
- ...Object.entries(process.env).filter(
201
- ([key]) => key.startsWith('NEXT_PUBLIC_') || key.startsWith('PNEXT_PUBLIC_'),
202
- ),
203
- ].map(([key, value]) => [
204
- `process.env.${key}`,
205
- value === undefined ? 'undefined' : JSON.stringify(value),
206
- ]),
207
- )
196
+ const publicEnv = Object.fromEntries([
197
+ // eslint-disable-next-line turbo/no-undeclared-env-vars
198
+ ['NODE_ENV', process.env.NODE_ENV ?? 'production'],
199
+ ...Object.entries(process.env).filter(
200
+ ([key]) => key.startsWith('NEXT_PUBLIC_') || key.startsWith('PNEXT_PUBLIC_'),
201
+ ),
202
+ ]) as Record<string, string>
203
+ return {
204
+ // The whole object, not just the keys that happen to be SET at build time. A browser has no
205
+ // `process`, so a `NEXT_PUBLIC_*` the source reads but the environment never defined would
206
+ // otherwise survive as a bare reference and throw ReferenceError on first evaluation - taking
207
+ // hydration, and every event handler on the page, down with it. Reading a missing key off this
208
+ // yields undefined, which is what Next inlines for one.
209
+ 'process.env': JSON.stringify(publicEnv),
210
+ ...Object.fromEntries(
211
+ Object.entries(publicEnv).map(([key, value]) => [
212
+ `process.env.${key}`,
213
+ JSON.stringify(value),
214
+ ]),
215
+ ),
216
+ }
208
217
  }
209
218
 
210
219
  type FrameworkRuntimeAlias =