vike 0.4.233 → 0.4.235

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.
@@ -165,9 +165,26 @@ async function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectF
165
165
  }
166
166
  function mergeScriptEntries(pageAssets, viteDevScript) {
167
167
  const scriptEntries = pageAssets.filter((pageAsset) => pageAsset.isEntry && pageAsset.assetType === 'script');
168
- const scriptTagsHtml = `${viteDevScript}${scriptEntries.map((asset) => (0, inferHtmlTags_js_1.inferAssetTag)(asset)).join('')}`;
169
- const scriptTag = (0, mergeScriptTags_js_1.mergeScriptTags)(scriptTagsHtml);
170
- return scriptTag;
168
+ let scriptEntry = `${viteDevScript}${scriptEntries.map((asset) => (0, inferHtmlTags_js_1.inferAssetTag)(asset)).join('')}`;
169
+ // We merge scripts to avoid the infamous HMR preamble error.
170
+ // - Infamous HMR preamble error:
171
+ // ```browser-console
172
+ // usePageContext.tsx:10 Uncaught (in promise) Error: @vitejs/plugin-react can't detect preamble. Something is wrong.
173
+ // at usePageContext.tsx:10:10
174
+ // ```
175
+ // - Note the following race condition. Maybe making the second script non-async ensures execution order?
176
+ // ```html
177
+ // <script type="module">console.log("I can be printed *after* the other log")</script>
178
+ // <script src="entry.js" type="module" async></script>
179
+ // ```
180
+ // ```js
181
+ // // entry.js
182
+ // console.log("I can be printed *before* the other log")
183
+ // ```
184
+ // - Maybe an alternative would be to make Vike's client runtime entry <script> tag non-async. Would that work? Would it be a performance issue?
185
+ // - The entry <script> shouldn't be `<script defer>` upon HTML streaming, otherwise progressive hydration while SSR streaming won't work.
186
+ scriptEntry = (0, mergeScriptTags_js_1.mergeScriptTags)(scriptEntry);
187
+ return scriptEntry;
171
188
  }
172
189
  function getPageContextJsonScriptTag(pageContext) {
173
190
  const pageContextClientSerialized = (0, sanitizeJson_js_1.sanitizeJson)((0, serializeContext_js_1.getPageContextClientSerialized)(pageContext));
@@ -21,7 +21,13 @@ function mergeScriptTags(scriptTagsHtml) {
21
21
  const hasInnerHtml = !!innerHtml.trim();
22
22
  if (src) {
23
23
  (0, utils_js_1.assert)(!hasInnerHtml);
24
- contents.push(`import ${JSON.stringify(src)};`);
24
+ // - We don't use a static import because static imports are hoisted => React's HMR preamble can be executed after user land code => triggering this error:
25
+ // ```
26
+ // [22:28:57.885][/test-dev.test.ts][pnpm run dev][Browser Error] Error: @vitejs/plugin-react-swc can't detect preamble. Something is wrong.
27
+ // at http://localhost:3000/@fs/home/rom/code/docpress/src/renderer/usePageContext.tsx:9:11
28
+ // ```
29
+ // - We don't use `await` the dynamic import() to avoid waterfall
30
+ contents.push(`import(${JSON.stringify(src)});`);
25
31
  }
26
32
  else if (hasInnerHtml) {
27
33
  innerHtml = innerHtml.split('\n').filter(Boolean).join('\n');
@@ -73,28 +73,33 @@ function handleFileAddRemove(server, config) {
73
73
  if ((0, transpileAndExecuteFile_js_1.isTemporaryBuildFile)(file))
74
74
  return;
75
75
  const { moduleGraph } = server;
76
- const isVikeConfig = await isVikeConfigDependency(file, moduleGraph);
76
+ const isVikeConfigDep = await isVikeConfigDependency(file, moduleGraph);
77
77
  const reload = () => reloadConfig(file, config, isRemove ? 'removed' : 'created', server);
78
- if (isVikeConfig) {
79
- if (isVikeConfig.isNotProcessedByVite) {
80
- reload();
81
- }
82
- else {
83
- // Let Vite handle it
84
- (0, utils_js_1.assert)(existsInViteModuleGraph(file, moduleGraph));
85
- }
78
+ // Config code
79
+ if (isVikeConfigDep && !isVikeConfigDep.isProcessedByVite) {
80
+ reload();
81
+ return;
86
82
  }
87
- else {
88
- // Trick: when importing a file that doesn't exist => we don't know whether `file` is that missing file => we take a leap of faith when the conditions below are met.
89
- // - Not sure how reliable that trick is.
90
- // - Reloading Vike's config is cheap and file creation/removal is rare => the trick is worth it.
91
- // - Reproduction:
92
- // ```bash
93
- // rm someDep.js && sleep 2 && git checkout someDep.js
94
- // ```
95
- if ((0, utils_js_1.isScriptFile)(file) && (0, getVikeConfigError_js_1.getVikeConfigError)() && !existsInViteModuleGraph(file, moduleGraph)) {
96
- reload();
97
- }
83
+ // New or deleted + file
84
+ if ((0, crawlPlusFiles_js_1.isPlusFile)(file)) {
85
+ reload();
86
+ return;
87
+ }
88
+ // Runtime code => let Vite handle it
89
+ if (isVikeConfigDep && isVikeConfigDep.isProcessedByVite) {
90
+ (0, utils_js_1.assert)(existsInViteModuleGraph(file, moduleGraph));
91
+ return;
92
+ }
93
+ // Trick: when importing a file that doesn't exist => we don't know whether `file` is that missing file => we take a leap of faith when the conditions below are met.
94
+ // - Not sure how reliable that trick is.
95
+ // - Reloading Vike's config is cheap and file creation/removal is rare => the trick is worth it.
96
+ // - Reproduction:
97
+ // ```bash
98
+ // rm someDep.js && sleep 2 && git checkout someDep.js
99
+ // ```
100
+ if ((0, utils_js_1.isScriptFile)(file) && (0, getVikeConfigError_js_1.getVikeConfigError)() && !existsInViteModuleGraph(file, moduleGraph)) {
101
+ reload();
102
+ return;
98
103
  }
99
104
  }
100
105
  }
@@ -107,9 +112,9 @@ function invalidateVikeVirtualFiles(server) {
107
112
  // Vite calls its hook handleHotUpdate() whenever *any file* is modified — including files that aren't in Vite's module graph such as `pages/+config.js`
108
113
  async function handleHotUpdate(ctx, config) {
109
114
  const { file, server } = ctx;
110
- const isVikeConfig = await isVikeConfigDependency(ctx.file, ctx.server.moduleGraph);
111
- if (isVikeConfig) {
112
- if (isVikeConfig.isNotProcessedByVite) {
115
+ const isVikeConfigDep = await isVikeConfigDependency(ctx.file, ctx.server.moduleGraph);
116
+ if (isVikeConfigDep) {
117
+ if (!isVikeConfigDep.isProcessedByVite) {
113
118
  /* Tailwind breaks this assertion, see https://github.com/vikejs/vike/discussions/1330#discussioncomment-7787238
114
119
  const isViteModule = ctx.modules.length > 0
115
120
  assert(!isViteModule)
@@ -139,7 +144,7 @@ async function isVikeConfigDependency(filePathAbsoluteFilesystem, moduleGraph) {
139
144
  const { _vikeConfigDependencies: vikeConfigDependencies } = vikeConfigObject;
140
145
  vikeConfigDependencies.forEach((f) => (0, utils_js_1.assertPosixPath)(f));
141
146
  if (vikeConfigDependencies.has(filePathAbsoluteFilesystem))
142
- return { isNotProcessedByVite: true };
147
+ return { isProcessedByVite: false };
143
148
  }
144
149
  // Runtime Vike config files such as +data.js which are processed by Vite.
145
150
  // - They're included in Vite's module graph.
@@ -148,7 +153,7 @@ async function isVikeConfigDependency(filePathAbsoluteFilesystem, moduleGraph) {
148
153
  const importers = getImporters(filePathAbsoluteFilesystem, moduleGraph);
149
154
  const isPlusValueFileDependency = Array.from(importers).some((importer) => importer.file && (0, crawlPlusFiles_js_1.isPlusFile)(importer.file));
150
155
  if (isPlusValueFileDependency)
151
- return { isNotProcessedByVite: false };
156
+ return { isProcessedByVite: true };
152
157
  return null;
153
158
  }
154
159
  function reloadConfig(filePath, config, op, server) {
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = void 0;
4
4
  // Automatically updated by @brillout/release-me
5
- exports.PROJECT_VERSION = '0.4.233';
5
+ exports.PROJECT_VERSION = '0.4.235';
@@ -156,7 +156,7 @@ declare function getPageContextBegin(isForErrorPage: boolean, { urlOriginal, isB
156
156
  declare global {
157
157
  var _vike: {
158
158
  fullyRenderedUrl?: string;
159
- };
159
+ } | undefined;
160
160
  }
161
161
  declare function disableClientRouting(err: unknown, log: boolean): void;
162
162
  declare function getRenderCount(): number;
@@ -160,9 +160,26 @@ async function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectF
160
160
  }
161
161
  function mergeScriptEntries(pageAssets, viteDevScript) {
162
162
  const scriptEntries = pageAssets.filter((pageAsset) => pageAsset.isEntry && pageAsset.assetType === 'script');
163
- const scriptTagsHtml = `${viteDevScript}${scriptEntries.map((asset) => inferAssetTag(asset)).join('')}`;
164
- const scriptTag = mergeScriptTags(scriptTagsHtml);
165
- return scriptTag;
163
+ let scriptEntry = `${viteDevScript}${scriptEntries.map((asset) => inferAssetTag(asset)).join('')}`;
164
+ // We merge scripts to avoid the infamous HMR preamble error.
165
+ // - Infamous HMR preamble error:
166
+ // ```browser-console
167
+ // usePageContext.tsx:10 Uncaught (in promise) Error: @vitejs/plugin-react can't detect preamble. Something is wrong.
168
+ // at usePageContext.tsx:10:10
169
+ // ```
170
+ // - Note the following race condition. Maybe making the second script non-async ensures execution order?
171
+ // ```html
172
+ // <script type="module">console.log("I can be printed *after* the other log")</script>
173
+ // <script src="entry.js" type="module" async></script>
174
+ // ```
175
+ // ```js
176
+ // // entry.js
177
+ // console.log("I can be printed *before* the other log")
178
+ // ```
179
+ // - Maybe an alternative would be to make Vike's client runtime entry <script> tag non-async. Would that work? Would it be a performance issue?
180
+ // - The entry <script> shouldn't be `<script defer>` upon HTML streaming, otherwise progressive hydration while SSR streaming won't work.
181
+ scriptEntry = mergeScriptTags(scriptEntry);
182
+ return scriptEntry;
166
183
  }
167
184
  function getPageContextJsonScriptTag(pageContext) {
168
185
  const pageContextClientSerialized = sanitizeJson(getPageContextClientSerialized(pageContext));
@@ -19,7 +19,13 @@ function mergeScriptTags(scriptTagsHtml) {
19
19
  const hasInnerHtml = !!innerHtml.trim();
20
20
  if (src) {
21
21
  assert(!hasInnerHtml);
22
- contents.push(`import ${JSON.stringify(src)};`);
22
+ // - We don't use a static import because static imports are hoisted => React's HMR preamble can be executed after user land code => triggering this error:
23
+ // ```
24
+ // [22:28:57.885][/test-dev.test.ts][pnpm run dev][Browser Error] Error: @vitejs/plugin-react-swc can't detect preamble. Something is wrong.
25
+ // at http://localhost:3000/@fs/home/rom/code/docpress/src/renderer/usePageContext.tsx:9:11
26
+ // ```
27
+ // - We don't use `await` the dynamic import() to avoid waterfall
28
+ contents.push(`import(${JSON.stringify(src)});`);
23
29
  }
24
30
  else if (hasInnerHtml) {
25
31
  innerHtml = innerHtml.split('\n').filter(Boolean).join('\n');
@@ -68,28 +68,33 @@ function handleFileAddRemove(server, config) {
68
68
  if (isTemporaryBuildFile(file))
69
69
  return;
70
70
  const { moduleGraph } = server;
71
- const isVikeConfig = await isVikeConfigDependency(file, moduleGraph);
71
+ const isVikeConfigDep = await isVikeConfigDependency(file, moduleGraph);
72
72
  const reload = () => reloadConfig(file, config, isRemove ? 'removed' : 'created', server);
73
- if (isVikeConfig) {
74
- if (isVikeConfig.isNotProcessedByVite) {
75
- reload();
76
- }
77
- else {
78
- // Let Vite handle it
79
- assert(existsInViteModuleGraph(file, moduleGraph));
80
- }
73
+ // Config code
74
+ if (isVikeConfigDep && !isVikeConfigDep.isProcessedByVite) {
75
+ reload();
76
+ return;
81
77
  }
82
- else {
83
- // Trick: when importing a file that doesn't exist => we don't know whether `file` is that missing file => we take a leap of faith when the conditions below are met.
84
- // - Not sure how reliable that trick is.
85
- // - Reloading Vike's config is cheap and file creation/removal is rare => the trick is worth it.
86
- // - Reproduction:
87
- // ```bash
88
- // rm someDep.js && sleep 2 && git checkout someDep.js
89
- // ```
90
- if (isScriptFile(file) && getVikeConfigError() && !existsInViteModuleGraph(file, moduleGraph)) {
91
- reload();
92
- }
78
+ // New or deleted + file
79
+ if (isPlusFile(file)) {
80
+ reload();
81
+ return;
82
+ }
83
+ // Runtime code => let Vite handle it
84
+ if (isVikeConfigDep && isVikeConfigDep.isProcessedByVite) {
85
+ assert(existsInViteModuleGraph(file, moduleGraph));
86
+ return;
87
+ }
88
+ // Trick: when importing a file that doesn't exist => we don't know whether `file` is that missing file => we take a leap of faith when the conditions below are met.
89
+ // - Not sure how reliable that trick is.
90
+ // - Reloading Vike's config is cheap and file creation/removal is rare => the trick is worth it.
91
+ // - Reproduction:
92
+ // ```bash
93
+ // rm someDep.js && sleep 2 && git checkout someDep.js
94
+ // ```
95
+ if (isScriptFile(file) && getVikeConfigError() && !existsInViteModuleGraph(file, moduleGraph)) {
96
+ reload();
97
+ return;
93
98
  }
94
99
  }
95
100
  }
@@ -102,9 +107,9 @@ function invalidateVikeVirtualFiles(server) {
102
107
  // Vite calls its hook handleHotUpdate() whenever *any file* is modified — including files that aren't in Vite's module graph such as `pages/+config.js`
103
108
  async function handleHotUpdate(ctx, config) {
104
109
  const { file, server } = ctx;
105
- const isVikeConfig = await isVikeConfigDependency(ctx.file, ctx.server.moduleGraph);
106
- if (isVikeConfig) {
107
- if (isVikeConfig.isNotProcessedByVite) {
110
+ const isVikeConfigDep = await isVikeConfigDependency(ctx.file, ctx.server.moduleGraph);
111
+ if (isVikeConfigDep) {
112
+ if (!isVikeConfigDep.isProcessedByVite) {
108
113
  /* Tailwind breaks this assertion, see https://github.com/vikejs/vike/discussions/1330#discussioncomment-7787238
109
114
  const isViteModule = ctx.modules.length > 0
110
115
  assert(!isViteModule)
@@ -134,7 +139,7 @@ async function isVikeConfigDependency(filePathAbsoluteFilesystem, moduleGraph) {
134
139
  const { _vikeConfigDependencies: vikeConfigDependencies } = vikeConfigObject;
135
140
  vikeConfigDependencies.forEach((f) => assertPosixPath(f));
136
141
  if (vikeConfigDependencies.has(filePathAbsoluteFilesystem))
137
- return { isNotProcessedByVite: true };
142
+ return { isProcessedByVite: false };
138
143
  }
139
144
  // Runtime Vike config files such as +data.js which are processed by Vite.
140
145
  // - They're included in Vite's module graph.
@@ -143,7 +148,7 @@ async function isVikeConfigDependency(filePathAbsoluteFilesystem, moduleGraph) {
143
148
  const importers = getImporters(filePathAbsoluteFilesystem, moduleGraph);
144
149
  const isPlusValueFileDependency = Array.from(importers).some((importer) => importer.file && isPlusFile(importer.file));
145
150
  if (isPlusValueFileDependency)
146
- return { isNotProcessedByVite: false };
151
+ return { isProcessedByVite: true };
147
152
  return null;
148
153
  }
149
154
  function reloadConfig(filePath, config, op, server) {
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.233";
1
+ export declare const PROJECT_VERSION: "0.4.235";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.233';
2
+ export const PROJECT_VERSION = '0.4.235';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.233",
3
+ "version": "0.4.235",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {