@wular/pnext 0.1.7 → 0.1.8

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 (172) hide show
  1. package/dist/server/_chunks/{aliases-j47a10ce.js → aliases-pycbtjt1.js} +7 -5
  2. package/dist/server/_chunks/{analyze-arswqe6s.js → analyze-4d9e00g9.js} +17 -13
  3. package/dist/server/_chunks/{boot-af0mv3dy.js → boot-bhemypxz.js} +13 -11
  4. package/dist/server/_chunks/{build-spy3dxp4.js → build-c991dv65.js} +7 -5
  5. package/dist/server/_chunks/{build-t9h0hec3.js → build-kh5e3x48.js} +977 -1186
  6. package/dist/server/_chunks/{build-tier-m7yvqz61.js → build-tier-0a96kmx3.js} +59 -75
  7. package/dist/server/_chunks/{compile-53j02j27.js → compile-040r79gj.js} +2 -2
  8. package/dist/server/_chunks/{config-n2z7yxps.js → config-0tvz03a6.js} +6 -4
  9. package/dist/server/_chunks/{config-1yzwexq6.js → config-27rj7830.js} +12 -3
  10. package/dist/server/_chunks/{create-meec9hs6.js → create-9rvwshsp.js} +4 -3
  11. package/dist/server/_chunks/{dev-fjmqg6en.js → dev-ex9exynt.js} +2 -2
  12. package/dist/server/_chunks/{generate-n9sh6hzt.js → generate-myw9hef7.js} +5 -4
  13. package/dist/server/_chunks/{index-91x12ykq.js → index-0r5eqfc7.js} +6 -1
  14. package/dist/server/_chunks/{index-3xbr4eyv.js → index-0yjv5v47.js} +3 -3
  15. package/dist/server/_chunks/{index-ncnes8c6.js → index-11xpbfej.js} +2 -2
  16. package/dist/server/_chunks/{index-357na4a8.js → index-141vcwk6.js} +1 -1
  17. package/dist/server/_chunks/{index-nyrba2kr.js → index-1pzm1hdy.js} +11 -11
  18. package/dist/server/_chunks/{index-fkp000p1.js → index-29pq0kax.js} +2 -2
  19. package/dist/server/_chunks/{index-wpfhfbs4.js → index-38xpdxwd.js} +4 -4
  20. package/dist/server/_chunks/{index-tvqkq6e6.js → index-3e075kny.js} +1 -1
  21. package/dist/server/_chunks/{index-kq8kpzye.js → index-3ycf5ckv.js} +3 -3
  22. package/dist/server/_chunks/{index-20ppawv7.js → index-4da76t62.js} +3 -3
  23. package/dist/server/_chunks/{index-cf4rvxv6.js → index-52k54ykj.js} +1 -1
  24. package/dist/server/_chunks/{index-x93hv0sc.js → index-71885zaq.js} +23 -10
  25. package/dist/server/_chunks/{index-jepjvcrf.js → index-8ct7rqy3.js} +1 -1
  26. package/dist/server/_chunks/{index-sjpckxqn.js → index-9f49w76j.js} +1 -1
  27. package/dist/server/_chunks/{index-4hgjrqh7.js → index-9hz3s0m8.js} +2 -2
  28. package/dist/server/_chunks/{index-9n2914ww.js → index-akkrvjn6.js} +1 -1
  29. package/dist/server/_chunks/{index-9ych9ma8.js → index-b7j671dj.js} +2 -2
  30. package/dist/server/_chunks/index-bzd2ef7t.js +10 -0
  31. package/dist/server/_chunks/{index-p77b4kcx.js → index-cn86z041.js} +1 -1
  32. package/dist/server/_chunks/{index-hkdfj58q.js → index-cvr4z22m.js} +1 -1
  33. package/dist/server/_chunks/{index-y2jr2n72.js → index-d158y67j.js} +4 -4
  34. package/dist/server/_chunks/{index-yz54pxrh.js → index-d1jsmhhk.js} +4 -9
  35. package/dist/server/_chunks/{index-ggk2j965.js → index-dgr390q7.js} +56 -50
  36. package/dist/server/_chunks/{index-sctcgyvv.js → index-drwv61cc.js} +2 -2
  37. package/dist/server/_chunks/{index-9hx2641q.js → index-entm8bmz.js} +1 -1
  38. package/dist/server/_chunks/{index-jx7bqvw1.js → index-evhd413j.js} +1 -1
  39. package/dist/server/_chunks/{index-1011cscr.js → index-fjv96re1.js} +61 -29
  40. package/dist/server/_chunks/{index-c0g2wf3z.js → index-gcmj16xy.js} +1 -1
  41. package/dist/server/_chunks/{index-ytjvpbm2.js → index-gkndxkxf.js} +3 -3
  42. package/dist/server/_chunks/index-hdbwtdv2.js +352 -0
  43. package/dist/server/_chunks/{index-z84ab1w0.js → index-he6n2bvp.js} +3 -3
  44. package/dist/server/_chunks/{index-eajaspjk.js → index-j0m1jxqa.js} +1 -1
  45. package/dist/server/_chunks/{index-4q2gbfwk.js → index-j681c48a.js} +2 -2
  46. package/dist/server/_chunks/index-jbj7ehef.js +50 -0
  47. package/dist/server/_chunks/{index-8k7pfejn.js → index-jn9rbhrx.js} +7 -7
  48. package/dist/server/_chunks/index-jt8e1pje.js +12 -0
  49. package/dist/server/_chunks/{index-eeaanp2e.js → index-kdhxpwyq.js} +3 -3
  50. package/dist/server/_chunks/{index-6e4fqv30.js → index-m63czgq5.js} +2 -0
  51. package/dist/server/_chunks/{index-2dv4y4wd.js → index-n629dy38.js} +16 -10
  52. package/dist/server/_chunks/{index-sv8m6789.js → index-nf3df4jy.js} +5 -5
  53. package/dist/server/_chunks/{index-06nyqntx.js → index-q3r9z8mq.js} +1 -1
  54. package/dist/server/_chunks/{index-3b3at80h.js → index-qcrvt6er.js} +6 -3
  55. package/dist/server/_chunks/{index-egykcqg3.js → index-rgj5mx84.js} +1 -1
  56. package/dist/server/_chunks/{index-vvmmknm1.js → index-rjegyfx4.js} +19 -15
  57. package/dist/server/_chunks/{index-ym67zqxp.js → index-tf4j19ge.js} +1 -1
  58. package/dist/server/_chunks/{index-5gyr4emz.js → index-tq3b39a5.js} +4 -4
  59. package/dist/server/_chunks/{index-qn4z5s3c.js → index-typcbcsv.js} +3 -3
  60. package/dist/server/_chunks/{index-11sfk4hb.js → index-vmr35jjw.js} +1 -1
  61. package/dist/server/_chunks/{index-danncfhy.js → index-wm36rj4v.js} +1 -1
  62. package/dist/server/_chunks/{index-3tf1xjsp.js → index-x2m17v9c.js} +11 -11
  63. package/dist/server/_chunks/{index-z4z9zv3b.js → index-x9c55pzy.js} +141 -3
  64. package/dist/server/_chunks/{index-k1g3epw0.js → index-xh1nbk46.js} +10 -10
  65. package/dist/server/_chunks/{index-0374j2b9.js → index-y4d02znn.js} +1 -1
  66. package/dist/server/_chunks/{index-qm6kmhqs.js → index-y7mzvq2q.js} +1 -1
  67. package/dist/server/_chunks/{index-rn8dyr1f.js → index-yrjkqtfj.js} +8 -48
  68. package/dist/server/_chunks/{index-tq0pc7eg.js → index-zfrwq472.js} +3 -3
  69. package/dist/server/_chunks/{loader-7yw0j98z.js → loader-5en7wpt5.js} +12 -10
  70. package/dist/server/_chunks/{modules-jn8bmbn8.js → modules-t92favpj.js} +14 -12
  71. package/dist/server/_chunks/{pipeline-yy9jhydf.js → pipeline-4t9q43ht.js} +25 -21
  72. package/dist/server/_chunks/{production-jar9ztm3.js → production-385bw8df.js} +14 -3
  73. package/dist/server/_chunks/{proxy-config-j84dgksn.js → proxy-config-60gprphe.js} +7 -5
  74. package/dist/server/_chunks/{proxy-w1d0wmsn.js → proxy-gfhmktbk.js} +12 -10
  75. package/dist/server/_chunks/{router-k1reahfn.js → router-xnrva921.js} +10 -7
  76. package/dist/server/_chunks/{routes-2s277fc6.js → routes-ht868pdc.js} +12 -10
  77. package/dist/server/_chunks/{run-pvd8bs1t.js → run-d40d63ag.js} +5 -4
  78. package/dist/server/_chunks/{server-mt4a994c.js → server-2p8fgqq2.js} +38 -34
  79. package/dist/server/_chunks/{tsconfig-defaults-1nb3308g.js → tsconfig-defaults-bcn34eqb.js} +5 -4
  80. package/dist/server/_chunks/{typegen-0qr0459b.js → typegen-dvtcjtaw.js} +15 -13
  81. package/dist/server/cli/index.js +12 -15
  82. package/dist/server/cli/start.js +35 -14
  83. package/dist/server/compat/next/cache.js +5 -5
  84. package/dist/server/compat/next/config-headers.js +8 -6
  85. package/dist/server/compat/next/config-loader.js +1 -1
  86. package/dist/server/compat/next/dist/server/web/spec-extension/revalidate.js +5 -5
  87. package/dist/server/compat/next/dist/server/web/spec-extension/unstable-cache.js +5 -5
  88. package/dist/server/compat/next/dist/server/web/spec-extension/unstable-no-store.js +5 -5
  89. package/dist/server/compat/next/dynamic.js +3 -14
  90. package/dist/server/compat/next/font/cache.js +6 -4
  91. package/dist/server/compat/next/font/local.js +7 -5
  92. package/dist/server/compat/next/font/runtime.js +7 -5
  93. package/dist/server/compat/next/headers.js +4 -4
  94. package/dist/server/compat/next/image/config.js +2 -2
  95. package/dist/server/compat/next/image/optimizer.js +3 -3
  96. package/dist/server/compat/next/image/static-metadata.js +4 -4
  97. package/dist/server/compat/next/legacy-request-apis.js +3 -3
  98. package/dist/server/compat/next/link-transform.js +4 -3
  99. package/dist/server/compat/next/navigation.js +5 -4
  100. package/dist/server/compat/next/redirects.js +8 -6
  101. package/dist/server/compat/next/resource-hints.js +2 -2
  102. package/dist/server/compat/next/rewrites.js +7 -5
  103. package/dist/server/compat/next/root-params.js +3 -3
  104. package/dist/server/compat/next/route-state.js +2 -2
  105. package/dist/server/compat/next/script.js +2 -2
  106. package/dist/server/compat/next/server.js +5 -5
  107. package/dist/server/generation.json +1 -1
  108. package/package.json +1 -1
  109. package/reference/compat.md +1 -1
  110. package/reference/config.md +2 -2
  111. package/reference/dev.md +1 -1
  112. package/reference/getting-started.md +1 -1
  113. package/reference/rendering.md +4 -4
  114. package/src/api/dynamic.tsx +84 -4
  115. package/src/cli/adapters/vercel-warm.ts +40 -29
  116. package/src/cli/adapters/vercel.ts +95 -1262
  117. package/src/cli/analyze.ts +3 -2
  118. package/src/cli/build/cache.ts +6 -6
  119. package/src/cli/build.ts +33 -33
  120. package/src/cli/index.ts +4 -6
  121. package/src/cli/serve/pipeline.ts +16 -10
  122. package/src/cli/serve/standalone-worker.ts +8 -0
  123. package/src/cli/serve/standalone.ts +703 -0
  124. package/src/cli/start.ts +29 -8
  125. package/src/client/build.ts +1 -1
  126. package/src/client/reference-stub.ts +2 -34
  127. package/src/compat/actions/extensions.ts +3 -2
  128. package/src/compat/bundler/require-context.ts +2 -1
  129. package/src/compat/bundler/webpack-loaders.ts +3 -2
  130. package/src/compat/bundler/worker.ts +2 -2
  131. package/src/compat/css/inline-css.ts +1 -1
  132. package/src/compat/export/build-complete.ts +1 -1
  133. package/src/compat/export/emit.ts +4 -4
  134. package/src/compat/export/standalone.ts +30 -65
  135. package/src/compat/image-optimizer/optimize.ts +1 -1
  136. package/src/compat/lifecycle/instrumentation-client.ts +4 -3
  137. package/src/compat/metadata-artifacts.ts +1 -1
  138. package/src/compat/next/config-loader.ts +3 -0
  139. package/src/compat/next/dynamic.tsx +10 -23
  140. package/src/compat/next/font/cache.ts +2 -1
  141. package/src/compat/next/font/runtime.ts +1 -1
  142. package/src/compat/register/image.ts +1 -1
  143. package/src/compat/typecheck/check.ts +6 -4
  144. package/src/config.ts +28 -5
  145. package/src/css/assets.ts +1 -1
  146. package/src/css/build.ts +16 -9
  147. package/src/dev/client-chunk-store.ts +2 -1
  148. package/src/dev/restart/client-key.ts +2 -1
  149. package/src/dev/restart/global-css.ts +2 -1
  150. package/src/dev/restart/route-bundle-key.ts +2 -1
  151. package/src/dev/restart/route-facts.ts +2 -1
  152. package/src/dev/server.ts +8 -7
  153. package/src/out-paths.ts +10 -0
  154. package/src/render/renderer.ts +1 -1
  155. package/src/resolve/dynamic.ts +4 -0
  156. package/src/resolve/engine.ts +2 -12
  157. package/src/resolve/scan-facts.ts +185 -1
  158. package/src/routing/metadata-files.ts +1 -1
  159. package/src/runtime/loader.ts +5 -3
  160. package/src/runtime/module-cache.ts +2 -1
  161. package/src/runtime/modules.ts +50 -16
  162. package/src/runtime/prebundle.ts +23 -3
  163. package/src/runtime/production.ts +105 -40
  164. package/src/runtime/release-graph.ts +21 -13
  165. package/src/runtime/vendor-build.ts +45 -23
  166. package/src/types.ts +2 -3
  167. package/src/utils/directive.ts +40 -0
  168. package/src/utils/fs.ts +7 -2
  169. package/src/utils/resource-query.ts +12 -0
  170. package/dist/server/_chunks/index-tqn2qnnn.js +0 -241
  171. package/dist/server/_chunks/index-y36a0ybw.js +0 -57
  172. package/src/cli/serve/entry.ts +0 -52
@@ -1,6 +1,6 @@
1
1
  /** @jsxImportSource preact */
2
- import { h, type ComponentType } from 'preact'
3
- import { useEffect, useRef, useState } from 'preact/hooks'
2
+ import { Component, h, type ComponentChildren, type ComponentType } from 'preact'
3
+ import { useEffect, useLayoutEffect, useRef, useState } from 'preact/hooks'
4
4
 
5
5
  export type DynamicModule<Props> = ComponentType<Props> | { default: ComponentType<Props> }
6
6
  export type DynamicLoader<Props> = string | (() => Promise<DynamicModule<Props>>)
@@ -35,6 +35,7 @@ export function dynamic<Props extends object = object>(
35
35
  ) {
36
36
  let loaded: ComponentType<Props> | null = null
37
37
  let pending: Promise<ComponentType<Props>> | null = null
38
+ let failed = false
38
39
  const loadModule =
39
40
  typeof loader === 'string'
40
41
  ? () => {
@@ -50,11 +51,45 @@ export function dynamic<Props extends object = object>(
50
51
  return pending
51
52
  }
52
53
 
53
- function DynamicComponent(props: Props) {
54
- const [Component, setComponent] = useState<ComponentType<Props> | null>(() => loaded)
54
+ // Rendered on the server and hydrated from its markup: suspends until the module loads.
55
+ function Loaded(props: Props) {
56
+ const ref = useRef<HTMLElement>(null)
57
+ const [remounts, setRemounts] = useState(0)
58
+ // The server sent `loading` because its load failed: replace that markup, never hydrate it.
59
+ useLayoutEffect(() => {
60
+ if (ref.current?.hasAttribute('data-pnext-loading')) setRemounts(1)
61
+ }, [])
62
+ if (loaded)
63
+ return h('pnext-dynamic', { key: remounts, ref, style: HOST_STYLE }, h(loaded, props))
64
+ const Loading = options.loading
65
+ if (failed) {
66
+ return h(
67
+ 'pnext-dynamic',
68
+ { ref, style: HOST_STYLE, 'data-pnext-loading': '' },
69
+ Loading ? h(Loading, props) : null,
70
+ )
71
+ }
72
+ // eslint-disable-next-line @typescript-eslint/only-throw-error
73
+ throw typeof window === 'undefined'
74
+ ? load().then(
75
+ () => undefined,
76
+ () => {
77
+ failed = true
78
+ },
79
+ )
80
+ : load()
81
+ }
82
+
83
+ function ClientDynamic(props: Props) {
84
+ const [Component, setComponent] = useState<ComponentType<Props> | null>(null)
55
85
  const [shouldLoad, setShouldLoad] = useState(() => options.load !== 'visible')
56
86
  const visibleRef = useRef<HTMLDivElement>(null)
57
87
 
88
+ // The server sent `loading`: hydrate it, then swap in a module that is already loaded.
89
+ useLayoutEffect(() => {
90
+ if (loaded) setComponent(() => loaded)
91
+ }, [])
92
+
58
93
  useEffect(() => {
59
94
  if (Component || shouldLoad) return
60
95
  const node = visibleRef.current
@@ -98,6 +133,18 @@ export function dynamic<Props extends object = object>(
98
133
  return Loading ? h(Loading, props) : null
99
134
  }
100
135
 
136
+ const DynamicComponent =
137
+ options.ssr === false || options.load === 'visible'
138
+ ? ClientDynamic
139
+ : (props: Props) =>
140
+ typeof window === 'undefined'
141
+ ? h(Loaded, props)
142
+ : h(
143
+ DynamicBoundary,
144
+ { fallback: options.loading ? h(options.loading, props) : null },
145
+ h(Loaded, props),
146
+ )
147
+
101
148
  ;(
102
149
  DynamicComponent as typeof DynamicComponent & {
103
150
  [dynamicReferenceSymbol]: DynamicReference<Props>
@@ -106,3 +153,36 @@ export function dynamic<Props extends object = object>(
106
153
 
107
154
  return DynamicComponent
108
155
  }
156
+
157
+ const HOST_STYLE = { display: 'contents' }
158
+ // preact's mangled MODE_HYDRATE flag on a vnode's `__u`.
159
+ const MODE_HYDRATE = 32
160
+
161
+ interface SuspendedVNode {
162
+ __u: number
163
+ }
164
+
165
+ // Suspense for one dynamic(): hydration keeps the server markup until the chunk loads, a fresh render
166
+ // shows `fallback`. `__c` is compat's mangled `_childDidSuspend`, so compat suspends here too.
167
+ class DynamicBoundary extends Component<
168
+ { fallback: ComponentChildren; children?: ComponentChildren },
169
+ { waiting?: boolean; held?: boolean }
170
+ > {
171
+ __c(promise: Promise<unknown>, vnode: SuspendedVNode) {
172
+ this.setState({ waiting: true, held: (vnode.__u & MODE_HYDRATE) !== 0 })
173
+ void promise.then(() => this.setState({ waiting: false }))
174
+ }
175
+
176
+ componentDidCatch(error: unknown) {
177
+ if (!(error instanceof Promise)) throw error
178
+ this.__c(error, (this as unknown as { __v: { __k: SuspendedVNode[] } }).__v.__k[0]!)
179
+ }
180
+
181
+ shouldComponentUpdate(_props: unknown, state: { waiting?: boolean; held?: boolean }) {
182
+ return !(state.waiting && state.held)
183
+ }
184
+
185
+ render() {
186
+ return this.state.waiting && !this.state.held ? this.props.fallback : this.props.children
187
+ }
188
+ }
@@ -29,10 +29,17 @@ import { existsSync } from 'node:fs'
29
29
  import { mkdir, readFile, rm } from 'node:fs/promises'
30
30
  import path from 'node:path'
31
31
  import { fileURLToPath } from 'node:url'
32
- import { DEFAULT_OUT_DIR, loadConfig, pathToFileHref, type ResolvedConfig } from '../../config'
32
+ import {
33
+ DEFAULT_OUT_DIR,
34
+ loadConfig,
35
+ pathToFileHref,
36
+ standaloneOutSegment,
37
+ type ResolvedConfig,
38
+ } from '../../config'
33
39
  import { bootstrapCompat } from '../../compat-bootstrap'
34
40
  import { compiledClientReferenceFiles, ssrClientReference } from '../../client/reference'
35
41
  import { hasUseClientDirective } from '../../client/reference-stub'
42
+ import { moduleExportNames } from '../../resolve/scan-facts'
36
43
  import { globalCssSources } from '../../css/build'
37
44
  import {
38
45
  devClientModuleHref,
@@ -61,6 +68,8 @@ import {
61
68
  releaseSourceKey,
62
69
  serializeReleaseConfig,
63
70
  writeBuildIndex,
71
+ buildManifestFile,
72
+ buildIndexFile,
64
73
  } from '../../runtime/production'
65
74
  import { frameworkFingerprint } from '../../runtime/fingerprint'
66
75
  import { releaseDependencyLog } from '../../runtime/vendor-build'
@@ -716,33 +725,35 @@ async function writeRelease(
716
725
  }
717
726
  const source = (file: string) => readSourceSync(file)
718
727
  const proxy = releasedProxy(config)
719
- await writeBuildIndex(
720
- config,
721
- {
722
- version: BUILD_INDEX_VERSION,
723
- framework: frameworkFingerprint(),
724
- config: serializeReleaseConfig(config),
725
- ...compat,
726
- modules,
727
- conventions,
728
- clientConventions: conventionFiles
729
- .filter(file => hasUseClientDirective(source(file)))
730
- .map(fromRoot),
731
- documentLayouts: conventionFiles
732
- .filter(
733
- file =>
734
- path.basename(file).startsWith('layout.') && /\bexport\s+default\b/.test(source(file)),
735
- )
736
- .map(fromRoot),
737
- globalCss: globalCss.map(fromRoot),
738
- ...(proxy ? { proxy: { ...proxy, file: fromRoot(proxy.file) } } : {}),
739
- ...(fonts ? { fonts } : {}),
740
- ...(dependencies.length > 0
741
- ? { dependencies: dependencies.map(file => toPosix(path.relative(config.outPath, file))) }
742
- : {}),
743
- },
744
- DEFAULT_OUT_DIR,
745
- )
728
+ await writeBuildIndex(config, {
729
+ version: BUILD_INDEX_VERSION,
730
+ framework: frameworkFingerprint(),
731
+ config: serializeReleaseConfig(config),
732
+ ...compat,
733
+ modules,
734
+ conventions,
735
+ clientConventions: conventionFiles
736
+ .filter(file => hasUseClientDirective(source(file)))
737
+ .map(fromRoot),
738
+ documentLayouts: conventionFiles
739
+ .filter(
740
+ file =>
741
+ path.basename(file).startsWith('layout.') &&
742
+ moduleExportNames(source(file), file).includes('default'),
743
+ )
744
+ .map(fromRoot),
745
+ globalCss: globalCss.map(fromRoot),
746
+ ...(proxy ? { proxy: { ...proxy, file: fromRoot(proxy.file) } } : {}),
747
+ ...(fonts ? { fonts } : {}),
748
+ ...(dependencies.length > 0
749
+ ? { dependencies: dependencies.map(file => toPosix(path.relative(config.outPath, file))) }
750
+ : {}),
751
+ })
752
+ // A build that moved outDir leaves no default-dir release behind for `pnext start` to serve.
753
+ const defaultRelease = path.join(config.root, DEFAULT_OUT_DIR, standaloneOutSegment)
754
+ if (path.resolve(config.outPath) !== defaultRelease) {
755
+ await rm(buildIndexFile(defaultRelease), { force: true })
756
+ }
746
757
  }
747
758
 
748
759
  /**
@@ -796,7 +807,7 @@ if (import.meta.main) {
796
807
  // A build that fails closes stdin without a go-ahead and never writes the manifest. There is
797
808
  // nothing to warm and nothing to report: exiting quietly keeps the failed build's own error the
798
809
  // only thing on stderr.
799
- const manifestFile = path.join(config.outPath, 'manifest.json')
810
+ const manifestFile = buildManifestFile(config.outPath)
800
811
  if (!request.skip || !existsSync(manifestFile)) process.exit(0)
801
812
  const manifest = resolveManifest(
802
813
  JSON.parse(await readFile(manifestFile, 'utf8')) as BuildManifest,