@revojs/vue 0.1.50 → 0.1.51

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.
@@ -7,6 +7,7 @@ interface AsyncOptions<T> {
7
7
  catch?: (error: T) => void | Promise<void>;
8
8
  }
9
9
  declare function useScope(): Scope;
10
+ declare function useError(scope?: Scope): ShallowRef<Error>;
10
11
  declare function useRouter(): {
11
12
  context: ShallowRef<RouterContext<Component>>;
12
13
  navigate: (path: string) => void;
@@ -28,6 +29,7 @@ declare function refreshAsync(input?: string | Array<string>): Promise<void[] |
28
29
  declare const isServerSideRendering: any;
29
30
  declare const REFRESH_ASYNC_HOOK: _$revojs.Descriptor<(names?: Array<string>) => Promise<void>>;
30
31
  declare const NAVIGATE_HOOK: _$revojs.Descriptor<_$revojs.Invoke>;
32
+ declare const CLIENT_ERROR_CONTEXT: _$revojs.Descriptor<ShallowRef<Error>>;
31
33
  declare const CLIENT_ROUTER_CONTEXT: _$revojs.Descriptor<ShallowRef<RouterContext<Component>>>;
32
34
  //#endregion
33
- export { AsyncOptions, CLIENT_ROUTER_CONTEXT, NAVIGATE_HOOK, REFRESH_ASYNC_HOOK, isServerSideRendering, refreshAsync, useAsync, useFetch, useRouter, useScope, useState };
35
+ export { AsyncOptions, CLIENT_ERROR_CONTEXT, CLIENT_ROUTER_CONTEXT, NAVIGATE_HOOK, REFRESH_ASYNC_HOOK, isServerSideRendering, refreshAsync, useAsync, useError, useFetch, useRouter, useScope, useState };
@@ -6,6 +6,9 @@ function useScope() {
6
6
  if (scope) return scope;
7
7
  throw new Error();
8
8
  }
9
+ function useError(scope = useScope()) {
10
+ return scope.getContext(CLIENT_ERROR_CONTEXT);
11
+ }
9
12
  function useRouter() {
10
13
  const scope = useScope();
11
14
  const context = scope.getContext(CLIENT_ROUTER_CONTEXT);
@@ -86,6 +89,7 @@ async function refreshAsync(input) {
86
89
  const isServerSideRendering = import.meta.SERVER_SIDE_RENDERING ?? globalThis?.import?.meta?.SERVER_SIDE_RENDERING;
87
90
  const REFRESH_ASYNC_HOOK = defineHook("REFRESH_ASYNC_HOOK");
88
91
  const NAVIGATE_HOOK = defineHook("NAVIGATE_HOOK");
92
+ const CLIENT_ERROR_CONTEXT = defineContext("CLIENT_ERROR_CONTEXT");
89
93
  const CLIENT_ROUTER_CONTEXT = defineContext("CLIENT_ROUTER_CONTEXT");
90
94
  //#endregion
91
- export { CLIENT_ROUTER_CONTEXT, NAVIGATE_HOOK, REFRESH_ASYNC_HOOK, isServerSideRendering, refreshAsync, useAsync, useFetch, useRouter, useScope, useState };
95
+ export { CLIENT_ERROR_CONTEXT, CLIENT_ROUTER_CONTEXT, NAVIGATE_HOOK, REFRESH_ASYNC_HOOK, isServerSideRendering, refreshAsync, useAsync, useError, useFetch, useRouter, useScope, useState };
@@ -1,9 +1,13 @@
1
1
  import Main from "#vue/main";
2
- import { createApp, createSSRApp } from "vue";
2
+ import { createApp, createSSRApp, warn } from "vue";
3
3
  import { isServerSideRendering } from "../client";
4
4
  //#region src/runtime/app.ts
5
5
  var app_default = async (scope) => {
6
6
  const app = (isServerSideRendering ? createSSRApp(Main) : createApp(Main)).provide("REVOJS_SCOPE", scope);
7
+ app.config.warnHandler = (message, instance, trace) => {
8
+ if (message.includes("Invalid vnode type when creating vnode") || message.includes("Component <Anonymous> is missing template or render function")) return;
9
+ warn(message, instance, trace);
10
+ };
7
11
  app.config.throwUnhandledErrorInProduction = true;
8
12
  return app;
9
13
  };
@@ -7,11 +7,12 @@
7
7
  <script setup lang="ts">
8
8
  import pages from "#pages";
9
9
  import { isClient, Router, RouterContext, useUrl } from "revojs";
10
- import { computed, h, onScopeDispose, shallowRef, type Component } from "vue";
11
- import { CLIENT_ROUTER_CONTEXT, NAVIGATE_HOOK, useScope } from "../client";
10
+ import { computed, h, onErrorCaptured, onScopeDispose, shallowRef, type Component } from "vue";
11
+ import { CLIENT_ERROR_CONTEXT, CLIENT_ROUTER_CONTEXT, NAVIGATE_HOOK, useScope } from "../client";
12
12
 
13
13
  const scope = useScope();
14
14
 
15
+ const error = shallowRef<Error>();
15
16
  const context = shallowRef<RouterContext<Component>>();
16
17
 
17
18
  const router = new Router<Component>();
@@ -32,9 +33,14 @@ for (const path in pages) {
32
33
 
33
34
  const route = computed(() => {
34
35
  if (context.value?.route.value) {
36
+ const route = h(context.value.route.value);
37
+
35
38
  return context.value.hooks.reduceRight(
36
- (previous, hook) => h(hook, null, { default: () => previous }),
37
- h(context.value.route.value),
39
+ (previous, hook) =>
40
+ h(hook, null, {
41
+ default: () => (error.value === undefined ? previous : undefined),
42
+ }),
43
+ route,
38
44
  );
39
45
  }
40
46
  });
@@ -54,5 +60,12 @@ if (isClient) {
54
60
 
55
61
  fetch();
56
62
 
63
+ scope.setContext(CLIENT_ERROR_CONTEXT, error);
57
64
  scope.setContext(CLIENT_ROUTER_CONTEXT, context);
65
+
66
+ onErrorCaptured((value) => {
67
+ if (error.value === undefined) {
68
+ error.value = value;
69
+ }
70
+ });
58
71
  </script>
@@ -1,4 +1,4 @@
1
- import { isServerSideRendering } from "../../../client";
1
+ import { isServerSideRendering, useError } from "../../../client";
2
2
  import createApp from "#vue/app";
3
3
  import { defineRoute, sendOk, useServer } from "revojs";
4
4
  import client from "#client";
@@ -9,10 +9,9 @@ var get_default = defineRoute({ async fetch(scope) {
9
9
  let content = client;
10
10
  if (isServerSideRendering) {
11
11
  const app = await createApp(scope);
12
- let exception;
13
- app.config.errorHandler = (value) => exception = value;
14
12
  content = content.replace("<!-- APP -->", await renderToString(app));
15
- if (exception) throw exception;
13
+ const error = useError(scope);
14
+ if (error.value) throw error.value;
16
15
  }
17
16
  const value = JSON.stringify(states).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
18
17
  return sendOk(scope, content.replace(`<!-- STATES -->`, value));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revojs/vue",
3
- "version": "0.1.50",
3
+ "version": "0.1.51",
4
4
  "license": "MIT",
5
5
  "repository": "tellua/revojs",
6
6
  "files": [