vocs 1.3.0 → 1.3.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # vocs
2
2
 
3
+ ## 1.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#357](https://github.com/wevm/vocs/pull/357) [`dc417ac`](https://github.com/wevm/vocs/commit/dc417ac51d256459a40e1188120def0070a20a36) Thanks [@tmm](https://github.com/tmm)! - Added handling for "Failed to fetch dynamically imported module" errors, which can be caused by version skew.
8
+
3
9
  ## 1.3.0
4
10
 
5
11
  ### Minor Changes
@@ -5,6 +5,7 @@ import { hydrateRoot } from 'react-dom/client';
5
5
  import { createBrowserRouter, RouterProvider } from 'react-router';
6
6
  import { ConfigProvider, getConfig } from './hooks/useConfig.js';
7
7
  import { routes } from './routes.js';
8
+ import { clearChunkReloadFlag } from './utils/chunkError.js';
8
9
  import { hydrateLazyRoutes } from './utils/hydrateLazyRoutes.js';
9
10
  import { removeTempStyles } from './utils/removeTempStyles.js';
10
11
  hydrate();
@@ -12,6 +13,7 @@ async function hydrate() {
12
13
  const basePath = getConfig().basePath;
13
14
  await hydrateLazyRoutes(routes, basePath);
14
15
  removeTempStyles();
16
+ clearChunkReloadFlag();
15
17
  const router = createBrowserRouter(routes, { basename: basePath });
16
18
  hydrateRoot(document.getElementById('app'), _jsx(ConfigProvider, { children: _jsx(NuqsAdapter, { children: _jsx(RouterProvider, { router: router }) }) }));
17
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.client.js","sourceRoot":"","sources":["../../app/index.client.tsx"],"names":[],"mappings":";AAAA,OAAO,uBAAuB,CAAA;AAE9B,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAClE,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AK,UAAU,OAAO;IACpB,MAAM,QAAQ,GAAG,SAAS,EAAE,CAAC,QAAQ,CAAA;IAErC,MAAM,iBAAiB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;IACzC,gBAAgB,EAAE,CAAA;IAClB,oBAAoB,EAAE,CAAA;IAEtB,MAAM,MAAM,GAAG,mBAAmB,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAA;IAClE,WAAW,CACT,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAE,EAC/B,KAAC,cAAc,cACb,KAAC,WAAW,cACV,KAAC,cAAc,IAAC,MAAM,EAAE,MAAM,GAAI,GACtB,GACC,CAClB,CAAA;AACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../app/routes.tsx"],"names":[],"mappings":"AAyCA,eAAO,MAAM,MAAM;;;;;;;;;;IA2BM,CAAA"}
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../app/routes.tsx"],"names":[],"mappings":"AA+CA,eAAO,MAAM,MAAM;;;;;;;;;;IAgCM,CAAA"}
@@ -3,17 +3,24 @@ import { routes as routes_virtual } from 'virtual:routes';
3
3
  import { NotFound } from './components/NotFound.js';
4
4
  import { DocsLayout } from './layouts/DocsLayout.js';
5
5
  import { Root } from './root.js';
6
+ import { maybeHandleChunkError } from './utils/chunkError.js';
6
7
  const notFoundRoute = (() => {
7
8
  const virtualRoute = routes_virtual.find(({ path }) => path === '*');
8
9
  if (virtualRoute)
9
10
  return {
10
11
  path: virtualRoute.path,
11
12
  lazy: async () => {
12
- const { frontmatter, ...route } = await virtualRoute.lazy();
13
- return {
14
- ...route,
15
- element: (_jsx(Root, { frontmatter: frontmatter, path: virtualRoute.path, children: _jsx(DocsLayout, { children: _jsx(route.default, {}) }) })),
16
- };
13
+ try {
14
+ const { frontmatter, ...route } = await virtualRoute.lazy();
15
+ return {
16
+ ...route,
17
+ element: (_jsx(Root, { frontmatter: frontmatter, path: virtualRoute.path, children: _jsx(DocsLayout, { children: _jsx(route.default, {}) }) })),
18
+ };
19
+ }
20
+ catch (error) {
21
+ maybeHandleChunkError(error);
22
+ throw error;
23
+ }
17
24
  },
18
25
  };
19
26
  return {
@@ -28,11 +35,17 @@ export const routes = [
28
35
  .map((route_virtual) => ({
29
36
  path: route_virtual.path,
30
37
  lazy: async () => {
31
- const { frontmatter, ...route } = await route_virtual.lazy();
32
- return {
33
- ...route,
34
- element: (_jsx(Root, { content: decodeURIComponent(route_virtual.content ?? ''), filePath: route_virtual.filePath, frontmatter: frontmatter, lastUpdatedAt: route_virtual.lastUpdatedAt, path: route_virtual.path, children: _jsx(DocsLayout, { children: _jsx(route.default, {}) }) })),
35
- };
38
+ try {
39
+ const { frontmatter, ...route } = await route_virtual.lazy();
40
+ return {
41
+ ...route,
42
+ element: (_jsx(Root, { content: decodeURIComponent(route_virtual.content ?? ''), filePath: route_virtual.filePath, frontmatter: frontmatter, lastUpdatedAt: route_virtual.lastUpdatedAt, path: route_virtual.path, children: _jsx(DocsLayout, { children: _jsx(route.default, {}) }) })),
43
+ };
44
+ }
45
+ catch (error) {
46
+ maybeHandleChunkError(error);
47
+ throw error;
48
+ }
36
49
  },
37
50
  })),
38
51
  notFoundRoute,
@@ -1 +1 @@
1
- {"version":3,"file":"routes.js","sourceRoot":"","sources":["../../app/routes.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAGzD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE;IAC1B,MAAM,YAAY,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,K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 -0,0 +1,4 @@
1
+ export declare function isChunkError(error: Error): boolean;
2
+ export declare function maybeHandleChunkError(error: Error): void;
3
+ export declare function clearChunkReloadFlag(): void;
4
+ //# sourceMappingURL=chunkError.d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunkError.d.ts","sourceRoot":"","sources":["../../../app/utils/chunkError.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,WASxC;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,KAAK,QAQjD;AAED,wBAAgB,oBAAoB,SAEnC"}
@@ -0,0 +1,26 @@
1
+ export function isChunkError(error) {
2
+ if (!error)
3
+ return false;
4
+ if (!error.message)
5
+ return false;
6
+ const message = error.message.toLowerCase();
7
+ return (message.includes('failed to fetch dynamically imported module') || // Chrome
8
+ message.includes('error loading dynamically imported module') || // Firefox/Safari
9
+ message.includes('dynamically imported module') // fallback
10
+ );
11
+ }
12
+ export function maybeHandleChunkError(error) {
13
+ if (!isChunkError(error))
14
+ return;
15
+ if (sessionStorage.getItem(reloadKey)) {
16
+ sessionStorage.removeItem(reloadKey);
17
+ return;
18
+ }
19
+ sessionStorage.setItem(reloadKey, 'true');
20
+ window.location.reload();
21
+ }
22
+ export function clearChunkReloadFlag() {
23
+ sessionStorage.removeItem(reloadKey);
24
+ }
25
+ const reloadKey = 'vocs.reload';
26
+ //# sourceMappingURL=chunkError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunkError.js","sourceRoot":"","sources":["../../../app/utils/chunkError.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY,CAAC,KAAY;IACvC,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAA;IACxB,IAAI,CAAC,KAAK,CAAC,OAAO;QAAE,OAAO,KAAK,CAAA;IAChC,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,CAAA;IAC3C,OAAO,CACL,OAAO,CAAC,QAAQ,CAAC,6CAA6C,CAAC,IAAI,SAAS;QAC5E,OAAO,CAAC,QAAQ,CAAC,2CAA2C,CAAC,IAAI,iBAAiB;QAClF,OAAO,CAAC,QAAQ,CAAC,6BAA6B,CAAC,CAAC,WAAW;KAC5D,CAAA;AACH,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,KAAY;IAChD,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;QAAE,OAAM;IAChC,IAAI,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACtC,cAAc,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;QACpC,OAAM;IACR,CAAC;IACD,cAAc,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;IACzC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAA;AAC1B,CAAC;AAED,MAAM,UAAU,oBAAoB;IAClC,cAAc,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;AACtC,CAAC;AAED,MAAM,SAAS,GAAG,aAAa,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"hydrateLazyRoutes.d.ts","sourceRoot":"","sources":["../../../app/utils/hydrateLazyRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,cAAc,CAAA;AAE5D,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,iBAiB1F"}
1
+ {"version":3,"file":"hydrateLazyRoutes.d.ts","sourceRoot":"","sources":["../../../app/utils/hydrateLazyRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,cAAc,CAAA;AAI5D,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,iBAsB1F"}
@@ -1,17 +1,23 @@
1
1
  import { matchRoutes } from 'react-router';
2
+ import { maybeHandleChunkError } from './chunkError.js';
2
3
  export async function hydrateLazyRoutes(routes, basePath) {
3
4
  // Determine if any of the initial routes are lazy
4
5
  const lazyMatches = matchRoutes(routes, window.location, basePath)?.filter((m) => m.route.lazy);
5
6
  // Load the lazy matches and update the routes before creating your router
6
7
  // so we can hydrate the SSR-rendered content synchronously
7
- if (lazyMatches && lazyMatches?.length > 0) {
8
- await Promise.all(lazyMatches.map(async (m) => {
9
- const routeModule = typeof m.route.lazy === 'function' ? await m.route.lazy() : m.route.lazy;
10
- Object.assign(m.route, {
11
- ...routeModule,
12
- lazy: undefined,
13
- });
14
- }));
15
- }
8
+ if (lazyMatches && lazyMatches?.length > 0)
9
+ try {
10
+ await Promise.all(lazyMatches.map(async (m) => {
11
+ const routeModule = typeof m.route.lazy === 'function' ? await m.route.lazy() : m.route.lazy;
12
+ Object.assign(m.route, {
13
+ ...routeModule,
14
+ lazy: undefined,
15
+ });
16
+ }));
17
+ }
18
+ catch (error) {
19
+ maybeHandleChunkError(error);
20
+ throw error;
21
+ }
16
22
  }
17
23
  //# sourceMappingURL=hydrateLazyRoutes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hydrateLazyRoutes.js","sourceRoot":"","sources":["../../../app/utils/hydrateLazyRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAoB,MAAM,cAAc,CAAA;AAE5D,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,MAAqB,EAAE,QAA4B;IACzF,kDAAkD;IAClD,MAAM,WAAW,GAAG,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAE/F,0EAA0E;IAC1E,2DAA2D;IAC3D,IAAI,WAAW,IAAI,WAAW,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3C,MAAM,OAAO,CAAC,GAAG,CACf,WAAW,CAAC,GAAG,CA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MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,EAAE;oBACrB,GAAG,WAAW;oBACd,IAAI,EAAE,SAAS;iBAChB,CAAC,CAAA;YACJ,CAAC,CAAC,CACH,CAAA;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,qBAAqB,CAAC,KAAc,CAAC,CAAA;YACrC,MAAM,KAAK,CAAA;QACb,CAAC;AACL,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const version = "1.3.0";
1
+ export declare const version = "1.3.1";
2
2
  //# sourceMappingURL=version.d.js.map
@@ -1,2 +1,2 @@
1
- export const version = '1.3.0';
1
+ export const version = '1.3.1';
2
2
  //# sourceMappingURL=version.js.map
@@ -5,6 +5,7 @@ import { hydrateRoot } from 'react-dom/client'
5
5
  import { createBrowserRouter, RouterProvider } from 'react-router'
6
6
  import { ConfigProvider, getConfig } from './hooks/useConfig.js'
7
7
  import { routes } from './routes.js'
8
+ import { clearChunkReloadFlag } from './utils/chunkError.js'
8
9
  import { hydrateLazyRoutes } from './utils/hydrateLazyRoutes.js'
9
10
  import { removeTempStyles } from './utils/removeTempStyles.js'
10
11
 
@@ -15,6 +16,7 @@ async function hydrate() {
15
16
 
16
17
  await hydrateLazyRoutes(routes, basePath)
17
18
  removeTempStyles()
19
+ clearChunkReloadFlag()
18
20
 
19
21
  const router = createBrowserRouter(routes, { basename: basePath })
20
22
  hydrateRoot(
package/app/routes.tsx CHANGED
@@ -4,6 +4,7 @@ import type { RouteObject } from 'react-router'
4
4
  import { NotFound } from './components/NotFound.js'
5
5
  import { DocsLayout } from './layouts/DocsLayout.js'
6
6
  import { Root } from './root.js'
7
+ import { maybeHandleChunkError } from './utils/chunkError.js'
7
8
 
8
9
  const notFoundRoute = (() => {
9
10
  const virtualRoute = routes_virtual.find(({ path }) => path === '*')
@@ -11,18 +12,23 @@ const notFoundRoute = (() => {
11
12
  return {
12
13
  path: virtualRoute.path,
13
14
  lazy: async () => {
14
- const { frontmatter, ...route } = await virtualRoute.lazy()
15
+ try {
16
+ const { frontmatter, ...route } = await virtualRoute.lazy()
15
17
 
16
- return {
17
- ...route,
18
- element: (
19
- <Root frontmatter={frontmatter} path={virtualRoute.path}>
20
- <DocsLayout>
21
- <route.default />
22
- </DocsLayout>
23
- </Root>
24
- ),
25
- } satisfies RouteObject
18
+ return {
19
+ ...route,
20
+ element: (
21
+ <Root frontmatter={frontmatter} path={virtualRoute.path}>
22
+ <DocsLayout>
23
+ <route.default />
24
+ </DocsLayout>
25
+ </Root>
26
+ ),
27
+ } satisfies RouteObject
28
+ } catch (error) {
29
+ maybeHandleChunkError(error as Error)
30
+ throw error
31
+ }
26
32
  },
27
33
  }
28
34
 
@@ -45,24 +51,29 @@ export const routes = [
45
51
  .map((route_virtual) => ({
46
52
  path: route_virtual.path,
47
53
  lazy: async () => {
48
- const { frontmatter, ...route } = await route_virtual.lazy()
54
+ try {
55
+ const { frontmatter, ...route } = await route_virtual.lazy()
49
56
 
50
- return {
51
- ...route,
52
- element: (
53
- <Root
54
- content={decodeURIComponent(route_virtual.content ?? '')}
55
- filePath={route_virtual.filePath}
56
- frontmatter={frontmatter}
57
- lastUpdatedAt={route_virtual.lastUpdatedAt}
58
- path={route_virtual.path}
59
- >
60
- <DocsLayout>
61
- <route.default />
62
- </DocsLayout>
63
- </Root>
64
- ),
65
- } satisfies RouteObject
57
+ return {
58
+ ...route,
59
+ element: (
60
+ <Root
61
+ content={decodeURIComponent(route_virtual.content ?? '')}
62
+ filePath={route_virtual.filePath}
63
+ frontmatter={frontmatter}
64
+ lastUpdatedAt={route_virtual.lastUpdatedAt}
65
+ path={route_virtual.path}
66
+ >
67
+ <DocsLayout>
68
+ <route.default />
69
+ </DocsLayout>
70
+ </Root>
71
+ ),
72
+ } satisfies RouteObject
73
+ } catch (error) {
74
+ maybeHandleChunkError(error as Error)
75
+ throw error
76
+ }
66
77
  },
67
78
  })),
68
79
  notFoundRoute,
@@ -0,0 +1,26 @@
1
+ export function isChunkError(error: Error) {
2
+ if (!error) return false
3
+ if (!error.message) return false
4
+ const message = error.message.toLowerCase()
5
+ return (
6
+ message.includes('failed to fetch dynamically imported module') || // Chrome
7
+ message.includes('error loading dynamically imported module') || // Firefox/Safari
8
+ message.includes('dynamically imported module') // fallback
9
+ )
10
+ }
11
+
12
+ export function maybeHandleChunkError(error: Error) {
13
+ if (!isChunkError(error)) return
14
+ if (sessionStorage.getItem(reloadKey)) {
15
+ sessionStorage.removeItem(reloadKey)
16
+ return
17
+ }
18
+ sessionStorage.setItem(reloadKey, 'true')
19
+ window.location.reload()
20
+ }
21
+
22
+ export function clearChunkReloadFlag() {
23
+ sessionStorage.removeItem(reloadKey)
24
+ }
25
+
26
+ const reloadKey = 'vocs.reload'
@@ -1,20 +1,27 @@
1
1
  import { matchRoutes, type RouteObject } from 'react-router'
2
2
 
3
+ import { maybeHandleChunkError } from './chunkError.js'
4
+
3
5
  export async function hydrateLazyRoutes(routes: RouteObject[], basePath: string | undefined) {
4
6
  // Determine if any of the initial routes are lazy
5
7
  const lazyMatches = matchRoutes(routes, window.location, basePath)?.filter((m) => m.route.lazy)
6
8
 
7
9
  // Load the lazy matches and update the routes before creating your router
8
10
  // so we can hydrate the SSR-rendered content synchronously
9
- if (lazyMatches && lazyMatches?.length > 0) {
10
- await Promise.all(
11
- lazyMatches.map(async (m) => {
12
- const routeModule = typeof m.route.lazy === 'function' ? await m.route.lazy() : m.route.lazy
13
- Object.assign(m.route, {
14
- ...routeModule,
15
- lazy: undefined,
16
- })
17
- }),
18
- )
19
- }
11
+ if (lazyMatches && lazyMatches?.length > 0)
12
+ try {
13
+ await Promise.all(
14
+ lazyMatches.map(async (m) => {
15
+ const routeModule =
16
+ typeof m.route.lazy === 'function' ? await m.route.lazy() : m.route.lazy
17
+ Object.assign(m.route, {
18
+ ...routeModule,
19
+ lazy: undefined,
20
+ })
21
+ }),
22
+ )
23
+ } catch (error) {
24
+ maybeHandleChunkError(error as Error)
25
+ throw error
26
+ }
20
27
  }
package/cli/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.3.0'
1
+ export const version = '1.3.1'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vocs",
3
3
  "description": "React Documentation Generator, powered by Vite.",
4
- "version": "1.3.0",
4
+ "version": "1.3.1",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "vocs": "./_lib/cli/index.js"