@react-router/dev 0.0.0-experimental-9c1812606 → 0.0.0-experimental-3278f3ca6

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 (53) hide show
  1. package/bin.js +1 -1
  2. package/dist/cli/commands.js +1 -1
  3. package/dist/cli/detectPackageManager.js +1 -1
  4. package/dist/cli/index.d.ts +1 -1
  5. package/dist/cli/index.js +7 -6
  6. package/dist/cli/run.js +1 -1
  7. package/dist/cli/useJavascript.js +1 -1
  8. package/dist/colors.js +1 -1
  9. package/dist/config/defaults/entry.client.tsx +1 -1
  10. package/dist/config/format.js +1 -1
  11. package/dist/config/routes.d.ts +77 -50
  12. package/dist/config/routes.js +175 -43
  13. package/dist/invariant.js +1 -1
  14. package/dist/routes.d.ts +2 -0
  15. package/dist/routes.js +23 -0
  16. package/dist/vite/babel.d.ts +10 -10
  17. package/dist/vite/babel.js +1 -1
  18. package/dist/vite/build.js +2 -2
  19. package/dist/vite/cloudflare-dev-proxy.d.ts +7 -1
  20. package/dist/vite/cloudflare-dev-proxy.js +14 -7
  21. package/dist/vite/cloudflare.d.ts +1 -0
  22. package/dist/vite/cloudflare.js +19 -0
  23. package/dist/vite/combine-urls.js +1 -1
  24. package/dist/{config.d.ts → vite/config.d.ts} +15 -24
  25. package/dist/{config.js → vite/config.js} +61 -39
  26. package/dist/vite/dev.js +1 -1
  27. package/dist/vite/import-vite-esm-sync.js +1 -1
  28. package/dist/vite/node-adapter.d.ts +1 -1
  29. package/dist/vite/node-adapter.js +7 -3
  30. package/dist/vite/plugin.d.ts +6 -3
  31. package/dist/vite/plugin.js +152 -103
  32. package/dist/vite/profiler.js +1 -1
  33. package/dist/vite/remove-exports.d.ts +2 -2
  34. package/dist/vite/remove-exports.js +113 -243
  35. package/dist/vite/resolve-file-url.js +1 -1
  36. package/dist/vite/static/refresh-utils.cjs +7 -26
  37. package/dist/vite/styles.d.ts +3 -2
  38. package/dist/vite/styles.js +23 -2
  39. package/dist/vite/vmod.js +1 -1
  40. package/dist/vite/with-props.d.ts +4 -0
  41. package/dist/vite/with-props.js +151 -0
  42. package/dist/vite.d.ts +2 -0
  43. package/dist/{cli.js → vite.js} +7 -8
  44. package/package.json +21 -12
  45. package/dist/cli.d.ts +0 -1
  46. package/dist/config/findConfig.d.ts +0 -1
  47. package/dist/config/findConfig.js +0 -32
  48. package/dist/config/flatRoutes.d.ts +0 -14
  49. package/dist/config/flatRoutes.js +0 -418
  50. package/dist/index.d.ts +0 -5
  51. package/dist/index.js +0 -23
  52. package/dist/vite/define-route.d.ts +0 -5
  53. package/dist/vite/define-route.js +0 -207
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-9c1812606
2
+ * @react-router/dev v0.0.0-experimental-3278f3ca6
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -12,267 +12,137 @@
12
12
 
13
13
  Object.defineProperty(exports, '__esModule', { value: true });
14
14
 
15
+ var babelDeadCodeElimination = require('babel-dead-code-elimination');
15
16
  var babel = require('./babel.js');
16
- var parser = require('@babel/parser');
17
- var t = require('@babel/types');
18
17
 
19
- function _interopNamespace(e) {
20
- if (e && e.__esModule) return e;
21
- var n = Object.create(null);
22
- if (e) {
23
- Object.keys(e).forEach(function (k) {
24
- if (k !== 'default') {
25
- var d = Object.getOwnPropertyDescriptor(e, k);
26
- Object.defineProperty(n, k, d.get ? d : {
27
- enumerable: true,
28
- get: function () { return e[k]; }
29
- });
18
+ const removeExports = (ast, exportsToRemove) => {
19
+ let previouslyReferencedIdentifiers = babelDeadCodeElimination.findReferencedIdentifiers(ast);
20
+ let exportsFiltered = false;
21
+ let markedForRemoval = new Set();
22
+ babel.traverse(ast, {
23
+ ExportDeclaration(path) {
24
+ // export { foo };
25
+ // export { bar } from "./module";
26
+ if (path.node.type === "ExportNamedDeclaration") {
27
+ var _path$node$declaratio, _path$node$declaratio2, _path$node$declaratio3;
28
+ if (path.node.specifiers.length) {
29
+ path.node.specifiers = path.node.specifiers.filter(specifier => {
30
+ // Filter out individual specifiers
31
+ if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
32
+ if (exportsToRemove.includes(specifier.exported.name)) {
33
+ exportsFiltered = true;
34
+ return false;
35
+ }
30
36
  }
31
- });
32
- }
33
- n["default"] = e;
34
- return Object.freeze(n);
35
- }
36
-
37
- var t__namespace = /*#__PURE__*/_interopNamespace(t);
38
-
39
- function getIdentifier(path) {
40
- let parentPath = path.parentPath;
41
- if (parentPath.type === "VariableDeclarator") {
42
- let variablePath = parentPath;
43
- let name = variablePath.get("id");
44
- return name.node.type === "Identifier" ? name : null;
45
- }
46
- if (parentPath.type === "AssignmentExpression") {
47
- let variablePath = parentPath;
48
- let name = variablePath.get("left");
49
- return name.node.type === "Identifier" ? name : null;
50
- }
51
- if (path.node.type === "ArrowFunctionExpression") {
52
- return null;
53
- }
54
- return path.node.id && path.node.id.type === "Identifier" ? path.get("id") : null;
55
- }
56
- function isIdentifierReferenced(ident) {
57
- let binding = ident.scope.getBinding(ident.node.name);
58
- if (binding !== null && binding !== void 0 && binding.referenced) {
59
- // Functions can reference themselves, so we need to check if there's a
60
- // binding outside the function scope or not.
61
- if (binding.path.type === "FunctionDeclaration") {
62
- return !binding.constantViolations.concat(binding.referencePaths)
63
- // Check that every reference is contained within the function:
64
- .every(ref => ref.findParent(parent => parent === (binding === null || binding === void 0 ? void 0 : binding.path)));
65
- }
66
- return true;
67
- }
68
- return false;
69
- }
70
- const removeExports = (source, exportsToRemove, generateOptions = {}) => {
71
- let document = parser.parse(source, {
72
- sourceType: "module"
73
- });
74
- let referencedIdentifiers = new Set();
75
- let removedExports = new Set();
76
- let markImport = path => {
77
- let local = path.get("local");
78
- if (isIdentifierReferenced(local)) {
79
- referencedIdentifiers.add(local);
80
- }
81
- };
82
- let markFunction = path => {
83
- let identifier = getIdentifier(path);
84
- if (identifier !== null && identifier !== void 0 && identifier.node && isIdentifierReferenced(identifier)) {
85
- referencedIdentifiers.add(identifier);
86
- }
87
- };
88
- babel.traverse(document, {
89
- VariableDeclarator(variablePath) {
90
- if (variablePath.node.id.type === "Identifier") {
91
- let local = variablePath.get("id");
92
- if (isIdentifierReferenced(local)) {
93
- referencedIdentifiers.add(local);
94
- }
95
- } else if (variablePath.node.id.type === "ObjectPattern") {
96
- let pattern = variablePath.get("id");
97
- let properties = pattern.get("properties");
98
- properties.forEach(p => {
99
- let local = p.get(p.node.type === "ObjectProperty" ? "value" : p.node.type === "RestElement" ? "argument" : function () {
100
- throw new Error("invariant");
101
- }());
102
- if (isIdentifierReferenced(local)) {
103
- referencedIdentifiers.add(local);
104
- }
105
- });
106
- } else if (variablePath.node.id.type === "ArrayPattern") {
107
- let pattern = variablePath.get("id");
108
- let elements = pattern.get("elements");
109
- elements.forEach(element => {
110
- var _element$node, _element$node2;
111
- let local;
112
- if (((_element$node = element.node) === null || _element$node === void 0 ? void 0 : _element$node.type) === "Identifier") {
113
- local = element;
114
- } else if (((_element$node2 = element.node) === null || _element$node2 === void 0 ? void 0 : _element$node2.type) === "RestElement") {
115
- local = element.get("argument");
116
- } else {
117
- return;
118
- }
119
- if (isIdentifierReferenced(local)) {
120
- referencedIdentifiers.add(local);
121
- }
122
- });
123
- }
124
- },
125
- FunctionDeclaration: markFunction,
126
- FunctionExpression: markFunction,
127
- ArrowFunctionExpression: markFunction,
128
- ImportSpecifier: markImport,
129
- ImportDefaultSpecifier: markImport,
130
- ImportNamespaceSpecifier: markImport,
131
- ExportNamedDeclaration(path) {
132
- let shouldRemove = false;
133
- // Handle re-exports: export { preload } from './foo'
134
- path.node.specifiers = path.node.specifiers.filter(spec => {
135
- if (spec.exported.type !== "Identifier") {
136
- return true;
137
- }
138
- let {
139
- name
140
- } = spec.exported;
141
- for (let namedExport of exportsToRemove) {
142
- if (name === namedExport) {
143
- removedExports.add(namedExport);
144
- return false;
37
+ return true;
38
+ });
39
+ // Remove the entire export statement if all specifiers were removed
40
+ if (path.node.specifiers.length === 0) {
41
+ markedForRemoval.add(path);
145
42
  }
146
43
  }
147
- return true;
148
- });
149
- let {
150
- declaration
151
- } = path.node;
152
- // When no re-exports are left, remove the path
153
- if (!declaration && path.node.specifiers.length === 0) {
154
- shouldRemove = true;
155
- }
156
- if (declaration && declaration.type === "VariableDeclaration") {
157
- declaration.declarations = declaration.declarations.filter(declarator => {
158
- for (let name of exportsToRemove) {
159
- if (declarator.id.name === name) {
160
- removedExports.add(name);
44
+ // export const foo = ...;
45
+ // export const [ foo ] = ...;
46
+ if (((_path$node$declaratio = path.node.declaration) === null || _path$node$declaratio === void 0 ? void 0 : _path$node$declaratio.type) === "VariableDeclaration") {
47
+ let declaration = path.node.declaration;
48
+ declaration.declarations = declaration.declarations.filter(declaration => {
49
+ // export const foo = ...;
50
+ // export const foo = ..., bar = ...;
51
+ if (declaration.id.type === "Identifier" && exportsToRemove.includes(declaration.id.name)) {
52
+ // Filter out individual variables
53
+ exportsFiltered = true;
161
54
  return false;
162
55
  }
56
+ // export const [ foo ] = ...;
57
+ // export const { foo } = ...;
58
+ if (declaration.id.type === "ArrayPattern" || declaration.id.type === "ObjectPattern") {
59
+ // NOTE: These exports cannot be safely removed, so instead we
60
+ // validate them to ensure that any exports that are intended to
61
+ // be removed are not present
62
+ validateDestructuredExports(declaration.id, exportsToRemove);
63
+ }
64
+ return true;
65
+ });
66
+ // Remove the entire export statement if all variables were removed
67
+ if (declaration.declarations.length === 0) {
68
+ markedForRemoval.add(path);
163
69
  }
164
- return true;
165
- });
166
- if (declaration.declarations.length === 0) {
167
- shouldRemove = true;
168
70
  }
169
- }
170
- if (declaration && declaration.type === "FunctionDeclaration") {
171
- for (let name of exportsToRemove) {
172
- var _declaration$id;
173
- if (((_declaration$id = declaration.id) === null || _declaration$id === void 0 ? void 0 : _declaration$id.name) === name) {
174
- shouldRemove = true;
175
- removedExports.add(name);
71
+ // export function foo() {}
72
+ if (((_path$node$declaratio2 = path.node.declaration) === null || _path$node$declaratio2 === void 0 ? void 0 : _path$node$declaratio2.type) === "FunctionDeclaration") {
73
+ let id = path.node.declaration.id;
74
+ if (id && exportsToRemove.includes(id.name)) {
75
+ markedForRemoval.add(path);
76
+ }
77
+ }
78
+ // export class Foo() {}
79
+ if (((_path$node$declaratio3 = path.node.declaration) === null || _path$node$declaratio3 === void 0 ? void 0 : _path$node$declaratio3.type) === "ClassDeclaration") {
80
+ let id = path.node.declaration.id;
81
+ if (id && exportsToRemove.includes(id.name)) {
82
+ markedForRemoval.add(path);
176
83
  }
177
84
  }
178
85
  }
179
- if (shouldRemove) {
180
- path.remove();
86
+ // export default ...;
87
+ if (path.node.type === "ExportDefaultDeclaration" && exportsToRemove.includes("default")) {
88
+ markedForRemoval.add(path);
181
89
  }
182
90
  }
183
91
  });
184
- if (removedExports.size === 0) {
185
- // No server-specific exports found so there's
186
- // no need to remove unused references
187
- return babel.generate(document, generateOptions);
92
+ if (markedForRemoval.size > 0 || exportsFiltered) {
93
+ for (let path of markedForRemoval) {
94
+ path.remove();
95
+ }
96
+ // Run dead code elimination on any newly unreferenced identifiers
97
+ babelDeadCodeElimination.deadCodeElimination(ast, previouslyReferencedIdentifiers);
188
98
  }
189
- let referencesRemovedInThisPass;
190
- let sweepFunction = path => {
191
- let identifier = getIdentifier(path);
192
- if (identifier !== null && identifier !== void 0 && identifier.node && referencedIdentifiers.has(identifier) && !isIdentifierReferenced(identifier)) {
193
- ++referencesRemovedInThisPass;
194
- if (t__namespace.isAssignmentExpression(path.parentPath.node) || t__namespace.isVariableDeclarator(path.parentPath.node)) {
195
- path.parentPath.remove();
196
- } else {
197
- path.remove();
99
+ };
100
+ function validateDestructuredExports(id, exportsToRemove) {
101
+ if (id.type === "ArrayPattern") {
102
+ for (let element of id.elements) {
103
+ if (!element) {
104
+ continue;
198
105
  }
199
- }
200
- };
201
- let sweepImport = path => {
202
- let local = path.get("local");
203
- if (referencedIdentifiers.has(local) && !isIdentifierReferenced(local)) {
204
- ++referencesRemovedInThisPass;
205
- path.remove();
206
- if (path.parent.specifiers.length === 0) {
207
- path.parentPath.remove();
106
+ // [ foo ]
107
+ if (element.type === "Identifier" && exportsToRemove.includes(element.name)) {
108
+ throw invalidDestructureError(element.name);
109
+ }
110
+ // [ ...foo ]
111
+ if (element.type === "RestElement" && element.argument.type === "Identifier" && exportsToRemove.includes(element.argument.name)) {
112
+ throw invalidDestructureError(element.argument.name);
113
+ }
114
+ // [ [...] ]
115
+ // [ {...} ]
116
+ if (element.type === "ArrayPattern" || element.type === "ObjectPattern") {
117
+ validateDestructuredExports(element, exportsToRemove);
208
118
  }
209
119
  }
210
- };
211
- // Traverse again to remove unused references. This happens at least once,
212
- // then repeats until no more references are removed.
213
- do {
214
- referencesRemovedInThisPass = 0;
215
- babel.traverse(document, {
216
- Program(path) {
217
- path.scope.crawl();
218
- },
219
- // eslint-disable-next-line no-loop-func
220
- VariableDeclarator(variablePath) {
221
- if (variablePath.node.id.type === "Identifier") {
222
- let local = variablePath.get("id");
223
- if (referencedIdentifiers.has(local) && !isIdentifierReferenced(local)) {
224
- ++referencesRemovedInThisPass;
225
- variablePath.remove();
226
- }
227
- } else if (variablePath.node.id.type === "ObjectPattern") {
228
- let pattern = variablePath.get("id");
229
- let beforeCount = referencesRemovedInThisPass;
230
- let properties = pattern.get("properties");
231
- properties.forEach(property => {
232
- let local = property.get(property.node.type === "ObjectProperty" ? "value" : property.node.type === "RestElement" ? "argument" : function () {
233
- throw new Error("invariant");
234
- }());
235
- if (referencedIdentifiers.has(local) && !isIdentifierReferenced(local)) {
236
- ++referencesRemovedInThisPass;
237
- property.remove();
238
- }
239
- });
240
- if (beforeCount !== referencesRemovedInThisPass && pattern.get("properties").length < 1) {
241
- variablePath.remove();
242
- }
243
- } else if (variablePath.node.id.type === "ArrayPattern") {
244
- let pattern = variablePath.get("id");
245
- let beforeCount = referencesRemovedInThisPass;
246
- let elements = pattern.get("elements");
247
- elements.forEach(e => {
248
- var _e$node, _e$node2;
249
- let local;
250
- if (((_e$node = e.node) === null || _e$node === void 0 ? void 0 : _e$node.type) === "Identifier") {
251
- local = e;
252
- } else if (((_e$node2 = e.node) === null || _e$node2 === void 0 ? void 0 : _e$node2.type) === "RestElement") {
253
- local = e.get("argument");
254
- } else {
255
- return;
256
- }
257
- if (referencedIdentifiers.has(local) && !isIdentifierReferenced(local)) {
258
- ++referencesRemovedInThisPass;
259
- e.remove();
260
- }
261
- });
262
- if (beforeCount !== referencesRemovedInThisPass && pattern.get("elements").length < 1) {
263
- variablePath.remove();
264
- }
120
+ }
121
+ if (id.type === "ObjectPattern") {
122
+ for (let property of id.properties) {
123
+ if (!property) {
124
+ continue;
125
+ }
126
+ if (property.type === "ObjectProperty" && property.key.type === "Identifier") {
127
+ // { foo }
128
+ if (property.value.type === "Identifier" && exportsToRemove.includes(property.value.name)) {
129
+ throw invalidDestructureError(property.value.name);
265
130
  }
266
- },
267
- FunctionDeclaration: sweepFunction,
268
- FunctionExpression: sweepFunction,
269
- ArrowFunctionExpression: sweepFunction,
270
- ImportSpecifier: sweepImport,
271
- ImportDefaultSpecifier: sweepImport,
272
- ImportNamespaceSpecifier: sweepImport
273
- });
274
- } while (referencesRemovedInThisPass);
275
- return babel.generate(document, generateOptions);
276
- };
131
+ // { foo: [...] }
132
+ // { foo: {...} }
133
+ if (property.value.type === "ArrayPattern" || property.value.type === "ObjectPattern") {
134
+ validateDestructuredExports(property.value, exportsToRemove);
135
+ }
136
+ }
137
+ // { ...foo }
138
+ if (property.type === "RestElement" && property.argument.type === "Identifier" && exportsToRemove.includes(property.argument.name)) {
139
+ throw invalidDestructureError(property.argument.name);
140
+ }
141
+ }
142
+ }
143
+ }
144
+ function invalidDestructureError(name) {
145
+ return new Error(`Cannot remove destructured export "${name}"`);
146
+ }
277
147
 
278
148
  exports.removeExports = removeExports;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-9c1812606
2
+ * @react-router/dev v0.0.0-experimental-3278f3ca6
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -60,7 +60,13 @@ const enqueueUpdate = debounce(async () => {
60
60
  window.__reactRouterRouteModuleUpdates.clear();
61
61
  }
62
62
 
63
- await revalidate();
63
+ try {
64
+ window.__remixHdrActive = true;
65
+ await __remixRouter.revalidate();
66
+ } finally {
67
+ window.__remixHdrActive = false;
68
+ }
69
+
64
70
  if (manifest) {
65
71
  Object.assign(window.__remixManifest, manifest);
66
72
  }
@@ -145,31 +151,6 @@ function __hmr_import(module) {
145
151
  const routeUpdates = new Map();
146
152
  window.__reactRouterRouteModuleUpdates = new Map();
147
153
 
148
- async function revalidate() {
149
- let { promise, resolve } = channel();
150
- let unsub = __remixRouter.subscribe((state) => {
151
- if (state.revalidation === "idle") {
152
- unsub();
153
- // Ensure RouterProvider setState has flushed before re-rendering
154
- resolve();
155
- }
156
- });
157
- window.__remixRevalidation = (window.__remixRevalidation || 0) + 1;
158
- __remixRouter.revalidate();
159
- return promise;
160
- }
161
-
162
- function channel() {
163
- let resolve;
164
- let reject;
165
-
166
- let promise = new Promise((_resolve, _reject) => {
167
- resolve = _resolve;
168
- reject = _reject;
169
- });
170
- return { promise, resolve, reject };
171
- }
172
-
173
154
  import.meta.hot.on("react-router:hmr", async ({ route }) => {
174
155
  window.__remixClearCriticalCss();
175
156
 
@@ -1,11 +1,12 @@
1
1
  import type { ServerBuild } from "react-router";
2
2
  import type { ViteDevServer } from "vite";
3
- import type { ResolvedVitePluginConfig } from "../config";
3
+ import type { ResolvedReactRouterConfig } from "./config";
4
4
  export declare const isCssModulesFile: (file: string) => boolean;
5
+ export declare const isCssUrlWithoutSideEffects: (url: string) => boolean;
5
6
  export declare const getStylesForUrl: ({ viteDevServer, rootDirectory, reactRouterConfig, entryClientFilePath, cssModulesManifest, build, url, }: {
6
7
  viteDevServer: ViteDevServer;
7
8
  rootDirectory: string;
8
- reactRouterConfig: Pick<ResolvedVitePluginConfig, "appDirectory" | "routes">;
9
+ reactRouterConfig: Pick<ResolvedReactRouterConfig, "appDirectory" | "routes">;
9
10
  entryClientFilePath: string;
10
11
  cssModulesManifest: Record<string, string>;
11
12
  build: ServerBuild;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-9c1812606
2
+ * @react-router/dev v0.0.0-experimental-3278f3ca6
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -44,6 +44,26 @@ const cssFileRegExp = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\
44
44
  const cssModulesRegExp = new RegExp(`\\.module${cssFileRegExp.source}`);
45
45
  const isCssFile = file => cssFileRegExp.test(file);
46
46
  const isCssModulesFile = file => cssModulesRegExp.test(file);
47
+ // https://vitejs.dev/guide/features#disabling-css-injection-into-the-page
48
+ // https://github.com/vitejs/vite/blob/561b940f6f963fbb78058a6e23b4adad53a2edb9/packages/vite/src/node/plugins/css.ts#L194
49
+ // https://vitejs.dev/guide/features#static-assets
50
+ // https://github.com/vitejs/vite/blob/561b940f6f963fbb78058a6e23b4adad53a2edb9/packages/vite/src/node/utils.ts#L309-L310
51
+ const cssUrlParamsWithoutSideEffects = ["url", "inline", "raw", "inline-css"];
52
+ const isCssUrlWithoutSideEffects = url => {
53
+ let queryString = url.split("?")[1];
54
+ if (!queryString) {
55
+ return false;
56
+ }
57
+ let params = new URLSearchParams(queryString);
58
+ for (let paramWithoutSideEffects of cssUrlParamsWithoutSideEffects) {
59
+ if (
60
+ // Parameter is blank and not explicitly set, i.e. "?url", not "?url="
61
+ params.get(paramWithoutSideEffects) === "" && !url.includes(`?${paramWithoutSideEffects}=`) && !url.includes(`&${paramWithoutSideEffects}=`)) {
62
+ return true;
63
+ }
64
+ }
65
+ return false;
66
+ };
47
67
  const getStylesForFiles = async ({
48
68
  viteDevServer,
49
69
  rootDirectory,
@@ -79,7 +99,7 @@ const getStylesForFiles = async ({
79
99
  console.error(err);
80
100
  }
81
101
  for (let dep of deps) {
82
- if (dep.file && isCssFile(dep.file) && !dep.url.endsWith("?url") // Ignore styles that resolved as URLs, otherwise we'll end up injecting URLs into the style tag contents
102
+ if (dep.file && isCssFile(dep.file) && !isCssUrlWithoutSideEffects(dep.url) // Ignore styles that resolved as URLs, inline or raw. These shouldn't get injected.
83
103
  ) {
84
104
  try {
85
105
  let css = isCssModulesFile(dep.file) ? cssModulesManifest[dep.file] : (await viteDevServer.ssrLoadModule(dep.url)).default;
@@ -174,3 +194,4 @@ const getStylesForUrl = async ({
174
194
 
175
195
  exports.getStylesForUrl = getStylesForUrl;
176
196
  exports.isCssModulesFile = isCssModulesFile;
197
+ exports.isCssUrlWithoutSideEffects = isCssUrlWithoutSideEffects;
package/dist/vite/vmod.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @react-router/dev v0.0.0-experimental-9c1812606
2
+ * @react-router/dev v0.0.0-experimental-3278f3ca6
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from "vite";
2
+ import type { Babel, ParseResult } from "./babel";
3
+ export declare const plugin: Plugin;
4
+ export declare const transform: (ast: ParseResult<Babel.File>) => void;
@@ -0,0 +1,151 @@
1
+ /**
2
+ * @react-router/dev v0.0.0-experimental-3278f3ca6
3
+ *
4
+ * Copyright (c) Remix Software Inc.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ 'use strict';
12
+
13
+ Object.defineProperty(exports, '__esModule', { value: true });
14
+
15
+ var dedent = require('dedent');
16
+ var babel = require('./babel.js');
17
+ var vmod = require('./vmod.js');
18
+ var t = require('@babel/types');
19
+
20
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
21
+
22
+ function _interopNamespace(e) {
23
+ if (e && e.__esModule) return e;
24
+ var n = Object.create(null);
25
+ if (e) {
26
+ Object.keys(e).forEach(function (k) {
27
+ if (k !== 'default') {
28
+ var d = Object.getOwnPropertyDescriptor(e, k);
29
+ Object.defineProperty(n, k, d.get ? d : {
30
+ enumerable: true,
31
+ get: function () { return e[k]; }
32
+ });
33
+ }
34
+ });
35
+ }
36
+ n["default"] = e;
37
+ return Object.freeze(n);
38
+ }
39
+
40
+ var dedent__default = /*#__PURE__*/_interopDefaultLegacy(dedent);
41
+ var t__namespace = /*#__PURE__*/_interopNamespace(t);
42
+
43
+ const vmodId = vmod.id("with-props");
44
+ const NAMED_COMPONENT_EXPORTS = ["HydrateFallback", "ErrorBoundary"];
45
+ const plugin = {
46
+ name: "react-router-with-props",
47
+ enforce: "pre",
48
+ resolveId(id) {
49
+ if (id === vmodId) return vmod.resolve(vmodId);
50
+ },
51
+ async load(id) {
52
+ if (id !== vmod.resolve(vmodId)) return;
53
+ return dedent__default["default"]`
54
+ import { createElement as h } from "react";
55
+ import { useActionData, useLoaderData, useParams } from "react-router";
56
+
57
+ export function withComponentProps(Component) {
58
+ return function Wrapped() {
59
+ const props = {
60
+ params: useParams(),
61
+ loaderData: useLoaderData(),
62
+ actionData: useActionData(),
63
+ };
64
+ return h(Component, props);
65
+ };
66
+ }
67
+
68
+ export function withHydrateFallbackProps(HydrateFallback) {
69
+ return function Wrapped() {
70
+ const props = {
71
+ params: useParams(),
72
+ };
73
+ return h(HydrateFallback, props);
74
+ };
75
+ }
76
+
77
+ export function withErrorBoundaryProps(ErrorBoundary) {
78
+ return function Wrapped() {
79
+ const props = {
80
+ params: useParams(),
81
+ loaderData: useLoaderData(),
82
+ actionData: useActionData(),
83
+ };
84
+ return h(ErrorBoundary, props);
85
+ };
86
+ }
87
+ `;
88
+ }
89
+ };
90
+ const transform = ast => {
91
+ const hocs = [];
92
+ function getHocUid(path, hocName) {
93
+ const uid = path.scope.generateUidIdentifier(hocName);
94
+ hocs.push([hocName, uid]);
95
+ return uid;
96
+ }
97
+ babel.traverse(ast, {
98
+ ExportDeclaration(path) {
99
+ if (path.isExportDefaultDeclaration()) {
100
+ const declaration = path.get("declaration");
101
+ // prettier-ignore
102
+ const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : undefined;
103
+ if (expr) {
104
+ const uid = getHocUid(path, "withComponentProps");
105
+ declaration.replaceWith(t__namespace.callExpression(uid, [expr]));
106
+ }
107
+ return;
108
+ }
109
+ if (path.isExportNamedDeclaration()) {
110
+ const decl = path.get("declaration");
111
+ if (decl.isVariableDeclaration()) {
112
+ decl.get("declarations").forEach(varDeclarator => {
113
+ const id = varDeclarator.get("id");
114
+ const init = varDeclarator.get("init");
115
+ const expr = init.node;
116
+ if (!expr) return;
117
+ if (!id.isIdentifier()) return;
118
+ const {
119
+ name
120
+ } = id.node;
121
+ if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
122
+ const uid = getHocUid(path, `with${name}Props`);
123
+ init.replaceWith(t__namespace.callExpression(uid, [expr]));
124
+ });
125
+ return;
126
+ }
127
+ if (decl.isFunctionDeclaration()) {
128
+ const {
129
+ id
130
+ } = decl.node;
131
+ if (!id) return;
132
+ const {
133
+ name
134
+ } = id;
135
+ if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
136
+ const uid = getHocUid(path, `with${name}Props`);
137
+ decl.replaceWith(t__namespace.variableDeclaration("const", [t__namespace.variableDeclarator(t__namespace.identifier(name), t__namespace.callExpression(uid, [toFunctionExpression(decl.node)]))]));
138
+ }
139
+ }
140
+ }
141
+ });
142
+ if (hocs.length > 0) {
143
+ ast.program.body.unshift(t__namespace.importDeclaration(hocs.map(([name, identifier]) => t__namespace.importSpecifier(identifier, t__namespace.identifier(name))), t__namespace.stringLiteral(vmodId)));
144
+ }
145
+ };
146
+ function toFunctionExpression(decl) {
147
+ return t__namespace.functionExpression(decl.id, decl.params, decl.body, decl.generator, decl.async);
148
+ }
149
+
150
+ exports.plugin = plugin;
151
+ exports.transform = transform;