vite-react-ssg 0.6.0 → 0.6.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/README.md CHANGED
@@ -13,6 +13,7 @@ See demo(also document): [docs](https://vite-react-ssg.netlify.app/)
13
13
  - [Extra route options](#extra-route-options)
14
14
  - [`entry`](#entry)
15
15
  - [`getStaticPaths`](#getstaticpaths)
16
+ - [Data fetch](#data-fetch)
16
17
  - [lazy](#lazy)
17
18
  - [`<ClientOnly/>`](#clientonly)
18
19
  - [Document head](#document-head)
@@ -135,7 +136,8 @@ The RouteObject of vite-react-ssg is based on react-router, and vite-react-ssg r
135
136
 
136
137
  #### `entry`
137
138
 
138
- Used to obtain static resources.If you introduce static resources (such as css files) in that route and use lazy loading (such as React.lazy or route.lazy), you should set the entry field. It should be the path from root to the target file.
139
+ Used to obtain static resources.If you introduce static resources (such as css files) in that route and use lazy loading (such as React.lazy or route.lazy), you should set the entry field.
140
+ It should be the path from root to the target file.
139
141
 
140
142
  eg: `src/pages/page1.tsx`
141
143
 
@@ -187,6 +189,12 @@ const routes = [
187
189
 
188
190
  See [example](./examples/lazy-pages/src/App.tsx).
189
191
 
192
+ ## Data fetch
193
+
194
+ You can use react-router-dom's `loader` to fetch data at build time and use `useLoaderData` to get the data in the component.
195
+
196
+ See [example | with-loader](./examples/with-loader/src/pages/[docs].tsx).
197
+
190
198
  ## `<ClientOnly/>`
191
199
 
192
200
  If you need to render some component in browser only, you can wrap your component with `<ClientOnly>`.
@@ -539,7 +547,6 @@ export default defineConfig({
539
547
  - [x] SSR in dev environment
540
548
  - [x] More Client components, such as `<ClientOnly />`
541
549
  - [x] `getStaticPaths` for dynamic routes
542
- - [ ] Initial State
543
550
 
544
551
  ## Credits
545
552
 
@@ -3,7 +3,7 @@
3
3
  const client = require('react-dom/client');
4
4
  const reactHelmetAsync = require('react-helmet-async');
5
5
  const React = require('react');
6
- const ClientOnly = require('../shared/vite-react-ssg.c639b3fe.cjs');
6
+ const ClientOnly = require('../shared/vite-react-ssg.c1d49976.cjs');
7
7
  const state = require('../shared/vite-react-ssg.e6991406.cjs');
8
8
 
9
9
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
@@ -1,8 +1,8 @@
1
1
  import { createRoot, hydrateRoot } from 'react-dom/client';
2
2
  import { HelmetProvider } from 'react-helmet-async';
3
3
  import React from 'react';
4
- import { d as documentReady } from '../shared/vite-react-ssg.8cdb31f1.mjs';
5
- export { C as ClientOnly, H as Head } from '../shared/vite-react-ssg.8cdb31f1.mjs';
4
+ import { d as documentReady } from '../shared/vite-react-ssg.a292c181.mjs';
5
+ export { C as ClientOnly, H as Head } from '../shared/vite-react-ssg.a292c181.mjs';
6
6
  import { d as deserializeState } from '../shared/vite-react-ssg.a009fbf1.mjs';
7
7
 
8
8
  function ViteReactSSG(App, fn, options = {}) {
package/dist/index.cjs CHANGED
@@ -4,7 +4,7 @@ const React = require('react');
4
4
  const client = require('react-dom/client');
5
5
  const reactHelmetAsync = require('react-helmet-async');
6
6
  const reactRouterDom = require('react-router-dom');
7
- const ClientOnly = require('./shared/vite-react-ssg.c639b3fe.cjs');
7
+ const ClientOnly = require('./shared/vite-react-ssg.c1d49976.cjs');
8
8
  const state = require('./shared/vite-react-ssg.e6991406.cjs');
9
9
 
10
10
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
package/dist/index.mjs CHANGED
@@ -2,8 +2,8 @@ import React, { forwardRef } from 'react';
2
2
  import { createRoot, hydrateRoot } from 'react-dom/client';
3
3
  import { HelmetProvider } from 'react-helmet-async';
4
4
  import { useLinkClickHandler, Link as Link$1, NavLink as NavLink$1, matchRoutes, createBrowserRouter, RouterProvider } from 'react-router-dom';
5
- import { d as documentReady } from './shared/vite-react-ssg.8cdb31f1.mjs';
6
- export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.8cdb31f1.mjs';
5
+ import { d as documentReady } from './shared/vite-react-ssg.a292c181.mjs';
6
+ export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.a292c181.mjs';
7
7
  import { d as deserializeState } from './shared/vite-react-ssg.a009fbf1.mjs';
8
8
 
9
9
  const Link = forwardRef((props, ref) => {
package/dist/node.cjs CHANGED
@@ -872,7 +872,7 @@ async function routesToPaths(routes) {
872
872
  for (const route of routes2) {
873
873
  let path = route.path;
874
874
  path = handlePath(path, prefix, route.entry);
875
- if (route.getStaticPaths && path?.includes(":")) {
875
+ if (route.getStaticPaths && isDynamicSegmentsRoute(path)) {
876
876
  const staticPaths = await route.getStaticPaths();
877
877
  for (let staticPath of staticPaths) {
878
878
  staticPath = handlePath(staticPath, prefix, route.entry);
@@ -964,6 +964,12 @@ const postfixRE = /[?#].*$/s;
964
964
  function cleanUrl(url) {
965
965
  return url.replace(postfixRE, "");
966
966
  }
967
+ const dynamicRE = /[:*?]/;
968
+ function isDynamicSegmentsRoute(route) {
969
+ if (!route)
970
+ return false;
971
+ return dynamicRE.test(route);
972
+ }
967
973
 
968
974
  async function getCritters(outDir, options = {}) {
969
975
  try {
package/dist/node.mjs CHANGED
@@ -863,7 +863,7 @@ async function routesToPaths(routes) {
863
863
  for (const route of routes2) {
864
864
  let path = route.path;
865
865
  path = handlePath(path, prefix, route.entry);
866
- if (route.getStaticPaths && path?.includes(":")) {
866
+ if (route.getStaticPaths && isDynamicSegmentsRoute(path)) {
867
867
  const staticPaths = await route.getStaticPaths();
868
868
  for (let staticPath of staticPaths) {
869
869
  staticPath = handlePath(staticPath, prefix, route.entry);
@@ -955,6 +955,12 @@ const postfixRE = /[?#].*$/s;
955
955
  function cleanUrl(url) {
956
956
  return url.replace(postfixRE, "");
957
957
  }
958
+ const dynamicRE = /[:*?]/;
959
+ function isDynamicSegmentsRoute(route) {
960
+ if (!route)
961
+ return false;
962
+ return dynamicRE.test(route);
963
+ }
958
964
 
959
965
  async function getCritters(outDir, options = {}) {
960
966
  try {
@@ -29,8 +29,10 @@ function ClientOnly({
29
29
  const isBrowser = useIsClient();
30
30
  if (isBrowser) {
31
31
  if (typeof children !== "function" && process.env.NODE_ENV === "development") {
32
- throw new Error(`vite-react-ssg error: The children of <ClientOnly> must be a "render function", e.g. <ClientOnly>{() => <span>{window.location.href}</span>}</ClientOnly>.
33
- Current type: ${isValidElement(children) ? "React element" : typeof children}`);
32
+ throw new Error(
33
+ `vite-react-ssg error: The children of <ClientOnly> must be a "render function", e.g. <ClientOnly>{() => <span>{window.location.href}</span>}</ClientOnly>.
34
+ Current type: ${isValidElement(children) ? "React element" : typeof children}`
35
+ );
34
36
  }
35
37
  return /* @__PURE__ */ React.createElement(React.Fragment, null, children?.());
36
38
  }
@@ -35,8 +35,10 @@ function ClientOnly({
35
35
  const isBrowser = useIsClient();
36
36
  if (isBrowser) {
37
37
  if (typeof children !== "function" && process.env.NODE_ENV === "development") {
38
- throw new Error(`vite-react-ssg error: The children of <ClientOnly> must be a "render function", e.g. <ClientOnly>{() => <span>{window.location.href}</span>}</ClientOnly>.
39
- Current type: ${React.isValidElement(children) ? "React element" : typeof children}`);
38
+ throw new Error(
39
+ `vite-react-ssg error: The children of <ClientOnly> must be a "render function", e.g. <ClientOnly>{() => <span>{window.location.href}</span>}</ClientOnly>.
40
+ Current type: ${React.isValidElement(children) ? "React element" : typeof children}`
41
+ );
40
42
  }
41
43
  return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, children?.());
42
44
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-react-ssg",
3
3
  "type": "module",
4
- "version": "0.6.0",
4
+ "version": "0.6.1",
5
5
  "packageManager": "pnpm@8.6.6",
6
6
  "description": "",
7
7
  "author": "Riri <Daydreamerriri@outlook.com>",
@@ -105,15 +105,15 @@
105
105
  "fs-extra": "^11.2.0",
106
106
  "html-minifier": "^4.0.0",
107
107
  "html5parser": "^2.0.2",
108
- "jsdom": "^23.0.1",
108
+ "jsdom": "^24.0.0",
109
109
  "kolorist": "^1.8.0",
110
- "prettier": "^3.0.0",
110
+ "prettier": "^3.2.4",
111
111
  "react-helmet-async": "^1.3.0",
112
112
  "yargs": "^17.7.2"
113
113
  },
114
114
  "devDependencies": {
115
115
  "@childrentime/devcert": "^1.2.5",
116
- "@ririd/eslint-config": "^1.0.0",
116
+ "@ririd/eslint-config": "^1.0.4",
117
117
  "@types/express": "^4.17.17",
118
118
  "@types/fs-extra": "^11.0.1",
119
119
  "@types/html-minifier": "^4.0.2",
@@ -122,12 +122,12 @@
122
122
  "@types/react": "^18.2.14",
123
123
  "@types/react-dom": "^18.2.6",
124
124
  "@types/yargs": "^17.0.24",
125
- "bumpp": "^9.1.0",
126
- "critters": "^0.0.20",
125
+ "bumpp": "^9.4.0",
126
+ "critters": "^0.0.22",
127
127
  "eslint": "^8.56.0",
128
- "esno": "^4.0.0",
129
- "fast-glob": "3.3.1",
130
- "p-queue": "^8.0.0",
128
+ "esno": "^4.7.0",
129
+ "fast-glob": "3.3.2",
130
+ "p-queue": "^8.0.1",
131
131
  "react": "^18.2.0",
132
132
  "react-dom": "^18.2.0",
133
133
  "react-router-dom": "^6.15.0",
@@ -135,7 +135,7 @@
135
135
  "styled-components": "6.0.5",
136
136
  "typescript": "5.1.6",
137
137
  "unbuild": "^2.0.0",
138
- "vite": "^5.0.7",
138
+ "vite": "^5.0.12",
139
139
  "vite-plugin-pwa": "^0.17.4",
140
140
  "vitest": "1.0.4"
141
141
  }