@octanejs/tanstack-start 0.1.1 → 0.1.5

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 (43) hide show
  1. package/package.json +13 -8
  2. package/src/GenericHydrate.tsrx +396 -0
  3. package/src/GenericHydrate.tsrx.d.ts +5 -0
  4. package/src/Hydrate.tsrx +106 -0
  5. package/src/Hydrate.tsrx.d.ts +63 -0
  6. package/src/client-only-server-strip.js +461 -0
  7. package/src/hydration/generic.d.ts +18 -0
  8. package/src/hydration/generic.js +26 -0
  9. package/src/hydration/idle.d.ts +9 -0
  10. package/src/hydration/idle.js +10 -0
  11. package/src/hydration/load.tsrx +38 -0
  12. package/src/hydration/load.tsrx.d.ts +8 -0
  13. package/src/hydration/never.tsrx +71 -0
  14. package/src/hydration/never.tsrx.d.ts +6 -0
  15. package/src/hydration/visible.tsrx +123 -0
  16. package/src/hydration/visible.tsrx.d.ts +12 -0
  17. package/src/hydration.d.ts +20 -0
  18. package/src/hydration.js +8 -0
  19. package/src/index.d.ts +11 -0
  20. package/src/index.js +2 -0
  21. package/src/internal/router-generator/filesystem/physical/getRouteNodes.js +4 -6
  22. package/src/internal/router-generator/generator.js +3 -0
  23. package/src/internal/router-plugin/core/code-splitter/compilers.js +3 -6
  24. package/src/internal/router-plugin/core/config.d.ts +1 -3
  25. package/src/internal/router-plugin/core/router-code-splitter-plugin.js +6 -3
  26. package/src/internal/router-plugin/esbuild.d.ts +4 -10
  27. package/src/internal/router-plugin/vite.d.ts +4 -10
  28. package/src/internal/start-plugin-core/import-protection/analysis.js +13 -12
  29. package/src/internal/start-plugin-core/import-protection/constants.d.ts +0 -1
  30. package/src/internal/start-plugin-core/import-protection/constants.js +0 -3
  31. package/src/internal/start-plugin-core/schema.d.ts +4 -14
  32. package/src/internal/start-plugin-core/start-compiler/compiler.d.ts +1 -6
  33. package/src/internal/start-plugin-core/start-compiler/compiler.js +4 -4
  34. package/src/internal/start-plugin-core/start-compiler/utils.d.ts +7 -0
  35. package/src/internal/start-plugin-core/start-compiler/utils.js +7 -0
  36. package/src/internal/start-plugin-core/types.d.ts +1 -2
  37. package/src/internal/start-plugin-core/vite/import-protection-plugin/plugin.js +21 -21
  38. package/src/internal/start-plugin-core/vite/module-id.d.ts +6 -0
  39. package/src/internal/start-plugin-core/vite/module-id.js +23 -0
  40. package/src/internal/start-plugin-core/vite/schema.d.ts +3 -12
  41. package/src/internal/start-plugin-core/vite/start-compiler-plugin/plugin.js +9 -3
  42. package/src/plugin-vite.d.ts +9 -1
  43. package/src/plugin-vite.js +20 -1
@@ -0,0 +1,6 @@
1
+ /** Checks for a query parameter without rewriting the opaque module ID. */
2
+ export declare function hasIdQueryFlag(id: string, flag: string): boolean;
3
+ /** Appends an owned query flag without normalizing the existing query. */
4
+ export declare function appendIdQueryFlag(id: string, flag: string): string;
5
+ /** Removes the owned query flag appended by {@link appendIdQueryFlag}. */
6
+ export declare function removeIdQueryFlag(id: string, flag: string): string;
@@ -0,0 +1,23 @@
1
+ //#region src/vite/module-id.ts
2
+ /** Checks for a query parameter without rewriting the opaque module ID. */
3
+ function hasIdQueryFlag(id, flag) {
4
+ const queryIndex = id.indexOf('?');
5
+ if (queryIndex === -1) return false;
6
+ return new URLSearchParams(id.slice(queryIndex + 1)).has(flag);
7
+ }
8
+ /** Appends an owned query flag without normalizing the existing query. */
9
+ function appendIdQueryFlag(id, flag) {
10
+ if (!id.includes('?')) return `${id}?${flag}`;
11
+ const separator = id.endsWith('&') ? '' : '&';
12
+ return `${id}${separator}${flag}`;
13
+ }
14
+ /** Removes the owned query flag appended by {@link appendIdQueryFlag}. */
15
+ function removeIdQueryFlag(id, flag) {
16
+ for (const separator of ['?', '&']) {
17
+ const suffix = `${separator}${flag}`;
18
+ if (id.endsWith(suffix)) return id.slice(0, -suffix.length);
19
+ }
20
+ return id;
21
+ }
22
+ //#endregion
23
+ export { appendIdQueryFlag, hasIdQueryFlag, removeIdQueryFlag };
@@ -1810,8 +1810,7 @@ export declare function parseStartConfig(
1810
1810
  base: string;
1811
1811
  disableCsrfMiddlewareWarning: boolean;
1812
1812
  generateFunctionId?:
1813
- | ((opts: { filename: string; functionName: string }) => string | undefined)
1814
- | undefined;
1813
+ ((opts: { filename: string; functionName: string }) => string | undefined) | undefined;
1815
1814
  };
1816
1815
  pages: {
1817
1816
  path: string;
@@ -1820,14 +1819,7 @@ export declare function parseStartConfig(
1820
1819
  exclude?: boolean | undefined;
1821
1820
  priority?: number | undefined;
1822
1821
  changefreq?:
1823
- | 'never'
1824
- | 'always'
1825
- | 'hourly'
1826
- | 'daily'
1827
- | 'weekly'
1828
- | 'monthly'
1829
- | 'yearly'
1830
- | undefined;
1822
+ 'never' | 'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | undefined;
1831
1823
  lastmod?: string | Date | undefined;
1832
1824
  alternateRefs?:
1833
1825
  | {
@@ -2390,8 +2382,7 @@ export declare function parseStartConfig(
2390
2382
  | undefined;
2391
2383
  mockAccess?: 'error' | 'warn' | 'off' | undefined;
2392
2384
  onViolation?:
2393
- | ((violation: unknown) => boolean | void | Promise<boolean | void>)
2394
- | undefined;
2385
+ ((violation: unknown) => boolean | void | Promise<boolean | void>) | undefined;
2395
2386
  include?: (string | RegExp)[] | undefined;
2396
2387
  exclude?: (string | RegExp)[] | undefined;
2397
2388
  client?:
@@ -15,6 +15,7 @@ import {
15
15
  MissingHydrateSourceError,
16
16
  createHydrateCompilerPlugin,
17
17
  } from '../../hydrate-when-transform.js';
18
+ import { appendIdQueryFlag, removeIdQueryFlag } from '../module-id.js';
18
19
  import {
19
20
  createViteDevServerFnModuleSpecifierEncoder,
20
21
  decodeViteDevServerModuleSpecifier,
@@ -184,7 +185,7 @@ function startCompilerPlugin(opts) {
184
185
  const code = await loadViteModuleFromEnvironment(this.environment, id, {
185
186
  load: (options) => this.load(options),
186
187
  error: (message) => this.error(message),
187
- devId: `${id}?${SERVER_FN_LOOKUP}`,
188
+ devId: appendIdQueryFlag(id, SERVER_FN_LOOKUP),
188
189
  });
189
190
  if (code !== void 0)
190
191
  compiler.ingestModule({
@@ -195,7 +196,12 @@ function startCompilerPlugin(opts) {
195
196
  resolveId: async (source, importer) => {
196
197
  const r = await this.resolve(source, importer);
197
198
  if (r) {
198
- if (!r.external) return cleanId(r.id);
199
+ if (!r.external) {
200
+ // Keep the resolved ID intact because it is passed back to
201
+ // Vite's load hook. Virtual-module prefixes and queries are
202
+ // part of that load identity, not compiler-only metadata.
203
+ return r.id;
204
+ }
199
205
  }
200
206
  return null;
201
207
  },
@@ -288,7 +294,7 @@ function startCompilerPlugin(opts) {
288
294
  handler(code, id) {
289
295
  compilers.get(this.environment.name)?.ingestModule({
290
296
  code,
291
- id: cleanId(id),
297
+ id: removeIdQueryFlag(id, SERVER_FN_LOOKUP),
292
298
  });
293
299
  },
294
300
  },
@@ -12,7 +12,15 @@ export type OctaneRendererDescriptor = Exclude<OctaneRendererRegistryEntry, stri
12
12
  export type OctaneRendererBoundary = OctaneRendererBoundaryOptions;
13
13
  export type OctaneRendererRule = OctaneRendererRuleOptions;
14
14
  export type OctaneRendererConfig = OctaneRendererConfigOptions;
15
- export type OctaneCompilerOptions = Omit<OctaneVitePluginOptions, 'ssr'>;
15
+ export type OctaneCompilerOptions = Omit<OctaneVitePluginOptions, 'ssr'> & {
16
+ /**
17
+ * Shorthand for the compiler's command-aware profiling signal (mirrors
18
+ * `@octanejs/vite-plugin`'s `devtools` option): enables profiling in `vite
19
+ * dev` only, fully compiled out of `vite build`. An explicit `profile`
20
+ * always takes precedence over `devtools`.
21
+ */
22
+ devtools?: boolean;
23
+ };
16
24
 
17
25
  export type TanStackOctaneStartViteInputConfig = TanStackStartViteInputConfig & {
18
26
  octane?: OctaneCompilerOptions;
@@ -1,6 +1,7 @@
1
1
  import { START_ENVIRONMENT_NAMES, tanStackStartVite } from '#tanstack-start/plugin-core/vite';
2
2
  import { octaneRouteGeneratorPlugin } from '@octanejs/tanstack-router/generator-plugin';
3
3
  import { octane } from 'octane/compiler/vite';
4
+ import { octaneClientOnlyServerStrip } from './client-only-server-strip.js';
4
5
  import { octaneStartDefaultEntryPaths } from './default-entry-paths.js';
5
6
  import { validateOctaneCompilerOptions } from './validate-options.js';
6
7
 
@@ -23,12 +24,27 @@ const WORKSPACE_SOURCE_EXCLUDES = [
23
24
  const WORKSPACE_SOURCE_INCLUDES = [
24
25
  '@octanejs/tanstack-router > @tanstack/router-core/isServer',
25
26
  '@octanejs/tanstack-router > @tanstack/router-core/scroll-restoration-script',
27
+ '@octanejs/tanstack-start > @tanstack/router-core/isServer',
26
28
  ];
27
29
 
28
30
  export function tanstackStart(options) {
29
31
  const { octane: octaneOptions, ...startOptions } = options ?? {};
30
32
  validateOctaneCompilerOptions(octaneOptions);
31
33
 
34
+ // `devtools: true` is Start's shorthand for the compiler's command-aware
35
+ // profiling signal (mirrors `@octanejs/vite-plugin`'s `devtools` option): an
36
+ // explicit `profile` always wins, otherwise `devtools` maps to `'auto'`
37
+ // (profiling on in `vite dev`, compiled out of `vite build`). `octane()`
38
+ // itself only understands `profile`, so this is resolved before the plugin
39
+ // is created and the `devtools` key never reaches it.
40
+ const resolvedOctaneOptions = octaneOptions ? { ...octaneOptions } : octaneOptions;
41
+ if (resolvedOctaneOptions) {
42
+ if (resolvedOctaneOptions.profile === undefined && resolvedOctaneOptions.devtools === true) {
43
+ resolvedOctaneOptions.profile = 'auto';
44
+ }
45
+ delete resolvedOctaneOptions.devtools;
46
+ }
47
+
32
48
  const corePluginOptions = {
33
49
  framework: 'octane',
34
50
  defaultEntryPaths: octaneStartDefaultEntryPaths,
@@ -39,7 +55,10 @@ export function tanstackStart(options) {
39
55
  };
40
56
 
41
57
  return [
42
- octane(octaneOptions),
58
+ // Must run before the octane compiler: strips <ClientOnly> children on
59
+ // the server (the octane analogue of start-compiler handleClientOnlyJSX).
60
+ octaneClientOnlyServerStrip(),
61
+ octane(resolvedOctaneOptions),
43
62
  {
44
63
  name: 'octanejs-tanstack-start:workspace-source-deps',
45
64
  configEnvironment(environmentName, environmentOptions) {