dtwo 3.1.2 → 3.2.1

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 (64) hide show
  1. package/LICENSE +21 -21
  2. package/app.d.ts +1 -1
  3. package/bin/dtwo.mjs +2 -2
  4. package/config.cjs +7 -7
  5. package/config.d.ts +2 -2
  6. package/config.mjs +5 -5
  7. package/dist/app/components/client-only.mjs +75 -75
  8. package/dist/app/components/dev-only.mjs +11 -11
  9. package/dist/app/components/dtwo-error-boundary.mjs +1 -1
  10. package/dist/app/components/dtwo-error-page.kdu +46 -46
  11. package/dist/app/components/dtwo-island.mjs +3 -1
  12. package/dist/app/components/dtwo-loading-indicator.mjs +5 -3
  13. package/dist/app/components/dtwo-root.kdu +5 -3
  14. package/dist/app/components/island-renderer.mjs +1 -1
  15. package/dist/app/components/layout.mjs +1 -1
  16. package/dist/app/composables/component.mjs +1 -1
  17. package/dist/app/composables/error.d.ts +1 -1
  18. package/dist/app/composables/fetch.d.ts +7 -6
  19. package/dist/app/composables/fetch.mjs +7 -1
  20. package/dist/app/composables/head.d.ts +2 -0
  21. package/dist/app/composables/head.mjs +1 -0
  22. package/dist/app/composables/index.d.ts +3 -1
  23. package/dist/app/composables/index.mjs +2 -1
  24. package/dist/app/composables/payload.mjs +6 -6
  25. package/dist/app/composables/preload.mjs +1 -1
  26. package/dist/app/composables/router.mjs +1 -1
  27. package/dist/app/composables/ssr.d.ts +1 -0
  28. package/dist/app/composables/ssr.mjs +7 -0
  29. package/dist/app/config.d.ts +1 -1
  30. package/dist/app/dtwo.d.ts +5 -2
  31. package/dist/app/dtwo.mjs +5 -0
  32. package/dist/app/entry-spa.d.ts +2 -0
  33. package/dist/app/entry-spa.mjs +2 -0
  34. package/dist/app/entry.mjs +1 -1
  35. package/dist/app/index.d.ts +0 -2
  36. package/dist/app/index.mjs +0 -1
  37. package/dist/app/plugins/chunk-reload.client.d.ts +2 -0
  38. package/dist/app/plugins/chunk-reload.client.mjs +26 -0
  39. package/dist/app/plugins/cross-origin-prefetch.client.mjs +2 -1
  40. package/dist/app/plugins/debug.mjs +1 -1
  41. package/dist/app/plugins/payload.client.mjs +3 -1
  42. package/dist/app/plugins/preload.server.mjs +1 -1
  43. package/dist/app/plugins/router.d.ts +1 -1
  44. package/dist/app/plugins/router.mjs +5 -2
  45. package/dist/app/types/augments.d.ts +28 -28
  46. package/dist/components/runtime/server-component.mjs +4 -1
  47. package/dist/core/runtime/hole/renderer.mjs +6 -2
  48. package/dist/head/runtime/composables.d.ts +1 -1
  49. package/dist/head/runtime/composables.mjs +1 -1
  50. package/dist/head/runtime/index.d.ts +1 -1
  51. package/dist/head/runtime/lib/kduse-head.plugin.mjs +1 -1
  52. package/dist/index.d.ts +1 -1
  53. package/dist/index.mjs +9173 -271
  54. package/dist/pages/runtime/app.kdu +5 -5
  55. package/dist/pages/runtime/page.mjs +1 -1
  56. package/dist/pages/runtime/plugins/prefetch.client.mjs +2 -1
  57. package/dist/pages/runtime/plugins/router.mjs +6 -2
  58. package/dist/pages/runtime/router.options.mjs +1 -1
  59. package/dist/pages/runtime/validate.mjs +23 -2
  60. package/package.json +31 -27
  61. package/schema.d.ts +1 -0
  62. package/schema.mjs +1 -0
  63. package/types.d.ts +1 -1
  64. package/README.md +0 -7
@@ -1,9 +1,9 @@
1
1
  import type { App, onErrorCaptured, KNode, Ref } from 'kdu';
2
2
  import type { Hookable } from 'hookable';
3
- import type { RuntimeConfig, AppConfigInput } from '@dtwo/schema';
4
3
  import type { SSRContext } from 'kdu-bundle-renderer/runtime';
5
4
  import type { H3Event } from 'h3';
6
5
  import type { DtwoIslandContext } from '../core/runtime/hole/renderer';
6
+ import type { RuntimeConfig, AppConfigInput } from 'dtwo/schema';
7
7
  type DtwoMeta = {
8
8
  htmlAttrs?: string;
9
9
  headAttrs?: string;
@@ -27,6 +27,9 @@ export interface RuntimeDtwoHooks {
27
27
  'app:error:cleared': (options: {
28
28
  redirect?: string;
29
29
  }) => HookResult;
30
+ 'app:chunkError': (options: {
31
+ error: any;
32
+ }) => HookResult;
30
33
  'app:data:refresh': (keys?: string[]) => HookResult;
31
34
  'link:prefetch': (link: string) => HookResult;
32
35
  'page:start': (Component?: KNode) => HookResult;
@@ -72,7 +75,7 @@ interface _DtwoApp {
72
75
  rendered?: Function;
73
76
  error?: Error | {
74
77
  url: string;
75
- statusCode: string;
78
+ statusCode: number;
76
79
  statusMessage: string;
77
80
  message: string;
78
81
  description: string;
package/dist/app/dtwo.mjs CHANGED
@@ -65,6 +65,11 @@ export function createDtwoApp(options) {
65
65
  app: options.ssrContext.runtimeConfig.app
66
66
  };
67
67
  }
68
+ if (process.client) {
69
+ window.addEventListener("dtwo.preloadError", (event) => {
70
+ dtwoApp.callHook("app:chunkError", { error: event.payload });
71
+ });
72
+ }
68
73
  const runtimeConfig = process.server ? options.ssrContext.runtimeConfig : reactive(dtwoApp.payload.config);
69
74
  const compatibilityConfig = new Proxy(runtimeConfig, {
70
75
  get(target, prop) {
@@ -0,0 +1,2 @@
1
+ declare const _default: () => void;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ export default () => {
2
+ };
@@ -1,7 +1,7 @@
1
1
  import { createSSRApp, createApp, nextTick } from "kdu";
2
2
  import { $fetch } from "ofetch";
3
3
  import { baseURL } from "#build/paths.mjs";
4
- import { createDtwoApp, applyPlugins, normalizePlugins } from "#app";
4
+ import { createDtwoApp, applyPlugins, normalizePlugins } from "#app/dtwo";
5
5
  import "#build/css";
6
6
  import _plugins from "#build/plugins";
7
7
  import RootComponent from "#build/root-component.mjs";
@@ -4,7 +4,5 @@ export * from './composables';
4
4
  export * from './components';
5
5
  export * from './config';
6
6
  export type { PageMeta } from '../pages/runtime';
7
- export type { MetaObject } from '../head/runtime';
8
- export { useHead } from '#head';
9
7
  export declare const isKdu2 = false;
10
8
  export declare const isKdu3 = true;
@@ -2,6 +2,5 @@ export * from "./dtwo.mjs";
2
2
  export * from "./composables/index.mjs";
3
3
  export * from "./components/index.mjs";
4
4
  export * from "./config.mjs";
5
- export { useHead } from "#head";
6
5
  export const isKdu2 = false;
7
6
  export const isKdu3 = true;
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,26 @@
1
+ import { defineDtwoPlugin } from "#app/dtwo";
2
+ import { useRouter } from "#app/composables/router";
3
+ export default defineDtwoPlugin((dtwoApp) => {
4
+ const router = useRouter();
5
+ const chunkErrors = /* @__PURE__ */ new Set();
6
+ router.beforeEach(() => {
7
+ chunkErrors.clear();
8
+ });
9
+ dtwoApp.hook("app:chunkError", ({ error }) => {
10
+ chunkErrors.add(error);
11
+ });
12
+ router.onError((error, to) => {
13
+ if (!chunkErrors.has(error)) {
14
+ return;
15
+ }
16
+ let handledPath = {};
17
+ try {
18
+ handledPath = JSON.parse(localStorage.getItem("dtwo:reload") || "{}");
19
+ } catch {
20
+ }
21
+ if (handledPath?.path !== to.fullPath || handledPath?.expires < Date.now()) {
22
+ localStorage.setItem("dtwo:reload", JSON.stringify({ path: to.fullPath, expires: Date.now() + 1e4 }));
23
+ window.location.href = to.fullPath;
24
+ }
25
+ });
26
+ });
@@ -1,6 +1,7 @@
1
1
  import { ref } from "kdu";
2
2
  import { parseURL } from "ufo";
3
- import { defineDtwoPlugin, useHead } from "#app";
3
+ import { defineDtwoPlugin } from "#app/dtwo";
4
+ import { useHead } from "#app/composables/head";
4
5
  export default defineDtwoPlugin((dtwoApp) => {
5
6
  const externalURLs = ref(/* @__PURE__ */ new Set());
6
7
  function generateRules() {
@@ -1,5 +1,5 @@
1
1
  import { createDebugger } from "hookable";
2
- import { defineDtwoPlugin } from "#app";
2
+ import { defineDtwoPlugin } from "#app/dtwo";
3
3
  export default defineDtwoPlugin((dtwoApp) => {
4
4
  createDebugger(dtwoApp.hooks, { tag: "dtwo-app" });
5
5
  });
@@ -1,5 +1,7 @@
1
1
  import { parseURL } from "ufo";
2
- import { defineDtwoPlugin, loadPayload, isPrerendered, useRouter } from "#app";
2
+ import { defineDtwoPlugin } from "#app/dtwo";
3
+ import { loadPayload, isPrerendered } from "#app/composables/payload";
4
+ import { useRouter } from "#app/composables/router";
3
5
  export default defineDtwoPlugin((dtwoApp) => {
4
6
  if (!isPrerendered()) {
5
7
  return;
@@ -1,4 +1,4 @@
1
- import { defineDtwoPlugin } from "#app";
1
+ import { defineDtwoPlugin } from "#app/dtwo";
2
2
  export default defineDtwoPlugin((dtwoApp) => {
3
3
  dtwoApp.kduApp.mixin({
4
4
  beforeCreate() {
@@ -46,7 +46,7 @@ interface Router {
46
46
  hasRoute: (name: string) => boolean;
47
47
  removeRoute: (name: string) => void;
48
48
  }
49
- declare const _default: import("..").Plugin<{
49
+ declare const _default: import("../dtwo").Plugin<{
50
50
  route: Route;
51
51
  router: Router;
52
52
  }>;
@@ -1,8 +1,11 @@
1
1
  import { reactive, h, isReadonly } from "kdu";
2
2
  import { parseURL, stringifyParsedURL, parseQuery, stringifyQuery, withoutBase, isEqual, joinURL } from "ufo";
3
3
  import { createError } from "h3";
4
- import { defineDtwoPlugin, clearError, navigateTo, showError, useRuntimeConfig, useState, useRequestEvent } from "../index.mjs";
5
- import { callWithDtwo } from "../dtwo.mjs";
4
+ import { callWithDtwo, defineDtwoPlugin, useRuntimeConfig } from "../dtwo.mjs";
5
+ import { clearError, showError } from "../composables/error.mjs";
6
+ import { navigateTo } from "../composables/router.mjs";
7
+ import { useState } from "../composables/state.mjs";
8
+ import { useRequestEvent } from "../composables/ssr.mjs";
6
9
  import { globalMiddleware } from "#build/middleware";
7
10
  function getRouteFromPath(fullPath) {
8
11
  if (typeof fullPath === "object") {
@@ -1,28 +1,28 @@
1
- import type { DtwoApp } from '../dtwo'
2
-
3
- declare global {
4
- namespace NodeJS {
5
- interface Process {
6
- browser: boolean
7
- client: boolean
8
- dev: boolean
9
- mode: 'spa' | 'universal'
10
- server: boolean
11
- static: boolean
12
- }
13
- }
14
-
15
- interface Window {
16
- __DTWO__?: Record<string, any>
17
- }
18
- }
19
-
20
- declare module 'kdu' {
21
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
22
- interface App<HostElement> {
23
- $dtwo: DtwoApp
24
- }
25
- interface ComponentInternalInstance {
26
- _dtwoOnBeforeMountCbs: Function[]
27
- }
28
- }
1
+ import type { DtwoApp } from '../dtwo'
2
+
3
+ declare global {
4
+ namespace NodeJS {
5
+ interface Process {
6
+ browser: boolean
7
+ client: boolean
8
+ dev: boolean
9
+ mode: 'spa' | 'universal'
10
+ server: boolean
11
+ static: boolean
12
+ }
13
+ }
14
+
15
+ interface Window {
16
+ __DTWO__?: Record<string, any>
17
+ }
18
+ }
19
+
20
+ declare module 'kdu' {
21
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
22
+ interface App<HostElement> {
23
+ $dtwo: DtwoApp
24
+ }
25
+ interface ComponentInternalInstance {
26
+ _dtwoOnBeforeMountCbs: Function[]
27
+ }
28
+ }
@@ -2,7 +2,10 @@ import { defineComponent, createStaticKNode, computed, h, watch } from "kdu";
2
2
  import { debounce } from "perfect-debounce";
3
3
  import { hash } from "ohash";
4
4
  import { appendHeader } from "h3";
5
- import { useAsyncData, useHead, useDtwoApp, useRequestEvent } from "#app";
5
+ import { useDtwoApp } from "#app/dtwo";
6
+ import { useRequestEvent } from "#app/composables/ssr";
7
+ import { useAsyncData } from "#app/composables/asyncData";
8
+ import { useHead } from "#app/composables/head";
6
9
  const pKey = "_islandPromises";
7
10
  export const createServerComponent = (name) => {
8
11
  return defineComponent({
@@ -4,8 +4,9 @@ import devalue from "@d2js/devalue";
4
4
  import destr from "destr";
5
5
  import { joinURL } from "ufo";
6
6
  import { renderToString as _renderToString } from "kdu/server-renderer";
7
- import { useRuntimeConfig, useHoleApp, defineRenderHandler, getRouteRules } from "#internal/hole";
7
+ import { useRuntimeConfig, defineRenderHandler, getRouteRules } from "#internal/hole";
8
8
  import { hash } from "ohash";
9
+ import { useHoleApp } from "#internal/hole/app";
9
10
  import { appRootId, appRootTag } from "#internal/dtwo.config.mjs";
10
11
  import { buildAssetsURL, publicAssetsURL } from "#paths";
11
12
  globalThis.__buildAssetsURL = buildAssetsURL;
@@ -31,7 +32,7 @@ const getSSRRenderer = lazyCachedFunction(async () => {
31
32
  const renderer = createRenderer(createSSRApp, options);
32
33
  async function renderToString(input, context) {
33
34
  const html = await _renderToString(input, context);
34
- if (process.dev && process.env.DTWO_WITE_NODE_OPTIONS) {
35
+ if (process.dev && process.env.DTWO_LAHM_NODE_OPTIONS) {
35
36
  renderer.rendererContext.updateManifest(await getClientManifest());
36
37
  }
37
38
  return `<${appRootTag} id="${appRootId}">${html}</${appRootTag}>`;
@@ -86,6 +87,9 @@ const PRERENDER_NO_SSR_ROUTES = /* @__PURE__ */ new Set(["/index.html", "/200.ht
86
87
  export default defineRenderHandler(async (event) => {
87
88
  const holeApp = useHoleApp();
88
89
  const ssrError = event.node.req.url?.startsWith("/__dtwo_error") ? getQuery(event) : null;
90
+ if (ssrError && ssrError.statusCode) {
91
+ ssrError.statusCode = parseInt(ssrError.statusCode);
92
+ }
89
93
  if (ssrError && event.node.req.socket.readyState !== "readOnly") {
90
94
  throw createError("Cannot directly render error page!");
91
95
  }
@@ -1,6 +1,6 @@
1
1
  import type { HeadEntryOptions, UseHeadInput, ActiveHeadEntry } from '@kduse/head';
2
- import type { HeadAugmentations } from '@dtwo/schema';
3
2
  import { useSeoMeta as _useSeoMeta } from '@kduse/head';
3
+ import type { HeadAugmentations } from 'dtwo/schema';
4
4
  /**
5
5
  * You can pass in a meta object, which has keys corresponding to meta tags:
6
6
  * `title`, `base`, `script`, `style`, `meta` and `link`, as well as `htmlAttrs` and `bodyAttrs`.
@@ -1,5 +1,5 @@
1
1
  import { useSeoMeta as _useSeoMeta } from "@kduse/head";
2
- import { useDtwoApp } from "#app";
2
+ import { useDtwoApp } from "#app/dtwo";
3
3
  export function useHead(input, options) {
4
4
  return useDtwoApp()._useHead(input, options);
5
5
  }
@@ -1,4 +1,4 @@
1
1
  import type { UseHeadInput } from '@kduse/head';
2
- import type { HeadAugmentations } from '@dtwo/schema';
2
+ import type { HeadAugmentations } from 'dtwo/schema';
3
3
  export * from './composables';
4
4
  export type MetaObject = UseHeadInput<HeadAugmentations>;
@@ -1,6 +1,6 @@
1
1
  import { createHead, useHead } from "@kduse/head";
2
2
  import { renderSSRHead } from "@kdhead/ssr";
3
- import { defineDtwoPlugin } from "#app";
3
+ import { defineDtwoPlugin } from "#app/dtwo";
4
4
  import { appHead } from "#build/dtwo.config.mjs";
5
5
  export default defineDtwoPlugin((dtwoApp) => {
6
6
  const head = createHead();
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { DtwoOptions, Dtwo } from '@dtwo/schema';
2
1
  import { LoadDtwoOptions } from '@dtwo/kit';
2
+ import { DtwoOptions, Dtwo } from 'dtwo/schema';
3
3
 
4
4
  declare function createDtwo(options: DtwoOptions): Dtwo;
5
5
  declare function loadDtwo(opts: LoadDtwoOptions): Promise<Dtwo>;