reflex 0.8.0a7__py3-none-any.whl → 0.8.0.post1__py3-none-any.whl

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.

Potentially problematic release.


This version of reflex might be problematic. Click here for more details.

@@ -0,0 +1,160 @@
1
+ /* vite-plugin-safari-cachebust.js
2
+ *
3
+ * Rewrite modulepreload <link> tags and ESM imports to include a cache-busting
4
+ * query parameter for Safari browser.
5
+ *
6
+ * https://github.com/remix-run/react-router/issues/12761
7
+ *
8
+ * The issue seems to be Safari over-aggressive caching of ESM imports (and modulepreload)
9
+ * which does not respect the cache-control headers sent by the server. This approach
10
+ * allows hot reload to work in Safari when adding routes or changing dependencies.
11
+ *
12
+ * No equivalent transformation is needed for production builds, as the
13
+ * output already contains the file hash in the name.
14
+ */
15
+
16
+ /**
17
+ * @typedef {import('vite').Plugin} Plugin
18
+ * @typedef {import('vite').ViteDevServer} ViteDevServer
19
+ * @typedef {import('http').IncomingMessage} IncomingMessage
20
+ * @typedef {import('http').ServerResponse} ServerResponse
21
+ * @typedef {import('connect').NextHandleFunction} NextHandleFunction
22
+ */
23
+
24
+ const pluginName = "vite-plugin-safari-cachebust";
25
+
26
+ /**
27
+ * Creates a Vite plugin that adds cache-busting for Safari browsers
28
+ * @returns {Plugin} The Vite plugin
29
+ */
30
+ export default function safariCacheBustPlugin() {
31
+ return {
32
+ name: pluginName,
33
+ /**
34
+ * Configure the dev server with the Safari middleware
35
+ * @param {ViteDevServer} server - The Vite dev server instance
36
+ */
37
+ configureServer(server) {
38
+ server.middlewares.use(createSafariMiddleware());
39
+ },
40
+ };
41
+ }
42
+
43
+ /**
44
+ * Determines if the user agent is Safari
45
+ * @param {string} ua - The user agent string
46
+ * @returns {boolean} True if the browser is Safari
47
+ */
48
+ function isSafari(ua) {
49
+ return /Safari/.test(ua) && !/Chrome/.test(ua);
50
+ }
51
+
52
+ /**
53
+ * Creates a middleware that adds cache-busting for Safari browsers
54
+ * @returns {NextHandleFunction} The middleware function
55
+ */
56
+ function createSafariMiddleware() {
57
+ // Set when a log message for rewriting n links has been emitted.
58
+ let _have_logged_n = -1;
59
+
60
+ /**
61
+ * Rewrites module import links in HTML content with cache-busting parameters
62
+ * @param {string} html - The HTML content to process
63
+ * @returns {string} The processed HTML content
64
+ */
65
+ function rewriteModuleImports(html) {
66
+ const currentTimestamp = new Date().getTime();
67
+ const parts = html.split(/(<link\s+rel="modulepreload"[^>]*>)/g);
68
+ /** @type {[string, string][]} */
69
+ const replacements = parts
70
+ .map((chunk) => {
71
+ const match = chunk.match(
72
+ /<link\s+rel="modulepreload"\s+href="([^"]+)"(.*?)\/?>/,
73
+ );
74
+ if (!match) return;
75
+
76
+ const [fullMatch, href, rest] = match;
77
+ if (/^(https?:)?\/\//.test(href)) return;
78
+
79
+ try {
80
+ const newHref = href.includes("?")
81
+ ? `${href}&__reflex_ts=${currentTimestamp}`
82
+ : `${href}?__reflex_ts=${currentTimestamp}`;
83
+ return [href, newHref];
84
+ } catch {
85
+ // no worries;
86
+ }
87
+ })
88
+ .filter(Boolean);
89
+ if (replacements.length && _have_logged_n !== replacements.length) {
90
+ _have_logged_n = replacements.length;
91
+ console.debug(
92
+ `[${pluginName}] Rewrote ${replacements.length} modulepreload links with __reflex_ts param.`,
93
+ );
94
+ }
95
+ return replacements.reduce((accumulator, [target, replacement]) => {
96
+ return accumulator.split(target).join(replacement);
97
+ }, html);
98
+ }
99
+
100
+ /**
101
+ * Middleware function to handle Safari cache busting
102
+ * @param {IncomingMessage} req - The incoming request
103
+ * @param {ServerResponse} res - The server response
104
+ * @param {(err?: any) => void} next - The next middleware function
105
+ * @returns {void}
106
+ */
107
+ return function safariCacheBustMiddleware(req, res, next) {
108
+ const ua = req.headers["user-agent"] || "";
109
+ // Remove our special cache bust query param to avoid affecting lower middleware layers.
110
+ if (
111
+ req.url &&
112
+ (req.url.includes("?__reflex_ts=") || req.url.includes("&__reflex_ts="))
113
+ ) {
114
+ req.url = req.url.replace(/(\?|&)__reflex_ts=\d+/, "");
115
+ return next();
116
+ }
117
+
118
+ // Only apply this middleware for Safari browsers.
119
+ if (!isSafari(ua)) return next();
120
+
121
+ // Only transform requests that want HTML.
122
+ const header_accept = req.headers["accept"] || "";
123
+ if (
124
+ typeof header_accept !== "string" ||
125
+ !header_accept.includes("text/html")
126
+ ) {
127
+ return next();
128
+ }
129
+
130
+ let buffer = "";
131
+ const _end = res.end.bind(res);
132
+
133
+ res.setHeader("x-modified-by", "vite-plugin-safari-cachebust");
134
+ /**
135
+ * Overridden write method to collect chunks
136
+ * @param {any} chunk - The chunk to write
137
+ * @param {...any} args - Additional arguments
138
+ * @returns {boolean} Result of the write operation
139
+ */
140
+ res.write = function (chunk, ...args) {
141
+ buffer += chunk instanceof Buffer ? chunk.toString("utf-8") : chunk;
142
+ return true;
143
+ };
144
+
145
+ /**
146
+ * Overridden end method to process and send the final response
147
+ * @param {any} chunk - The final chunk to write
148
+ * @param {...any} args - Additional arguments
149
+ * @returns {ServerResponse<IncomingMessage>} The server response
150
+ */
151
+ res.end = function (chunk, ...args) {
152
+ if (chunk) {
153
+ buffer += chunk instanceof Buffer ? chunk.toString("utf-8") : chunk;
154
+ }
155
+ buffer = rewriteModuleImports(buffer);
156
+ return _end(buffer, ...args);
157
+ };
158
+ return next();
159
+ };
160
+ }
@@ -1,9 +1,10 @@
1
1
  import { fileURLToPath, URL } from "url";
2
2
  import { reactRouter } from "@react-router/dev/vite";
3
3
  import { defineConfig } from "vite";
4
+ import safariCacheBustPlugin from "./vite-plugin-safari-cachebust";
4
5
 
5
6
  export default defineConfig((config) => ({
6
- plugins: [reactRouter()],
7
+ plugins: [reactRouter(), safariCacheBustPlugin()],
7
8
  build: {
8
9
  rollupOptions: {
9
10
  jsx: {},
@@ -149,4 +149,5 @@ class PackageJson(SimpleNamespace):
149
149
  # This should always match the `react` version in DEPENDENCIES for recharts compatibility.
150
150
  "react-is": _react_version,
151
151
  "cookie": "1.0.2",
152
+ "rollup": "4.44.2",
152
153
  }
reflex/utils/processes.py CHANGED
@@ -15,6 +15,7 @@ from pathlib import Path
15
15
  from typing import Any, Literal, overload
16
16
 
17
17
  import click
18
+ import rich.markup
18
19
  from redis.exceptions import RedisError
19
20
  from rich.progress import Progress
20
21
 
@@ -281,7 +282,7 @@ def stream_logs(
281
282
  return
282
283
  try:
283
284
  for line in process.stdout:
284
- console.debug(line, end="", progress=progress)
285
+ console.debug(rich.markup.escape(line), end="", progress=progress)
285
286
  logs.append(line)
286
287
  yield line
287
288
  except ValueError:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reflex
3
- Version: 0.8.0a7
3
+ Version: 0.8.0.post1
4
4
  Summary: Web apps in pure Python.
5
5
  Project-URL: homepage, https://reflex.dev
6
6
  Project-URL: repository, https://github.com/reflex-dev/reflex
@@ -43,7 +43,8 @@ reflex/.templates/web/.gitignore,sha256=3tT0CtVkCL09D_Y3Hd4myUgGcBuESeavCa0WHU5i
43
43
  reflex/.templates/web/jsconfig.json,sha256=rhQZZRBYxBWclFYTeU6UakzbGveM4qyRQZUpEAVhyqY,118
44
44
  reflex/.templates/web/postcss.config.js,sha256=6Hf540Ny078yfmJ_-tniZtmgHW6euyEyxO0zH-Y1EtQ,86
45
45
  reflex/.templates/web/react-router.config.js,sha256=5K1FBryYdPusn1nE513GwB5_5UdPzoyH8ZMANUbpodQ,84
46
- reflex/.templates/web/vite.config.js,sha256=48pSybaKFRmbeR2n7ead5ppJZxEpDPJQUB8jD9jbfEM,890
46
+ reflex/.templates/web/vite-plugin-safari-cachebust.js,sha256=FcyppYYBxUlZtQ-D_iyVaQIT6TBVisBH7DMzWxYm-zA,5300
47
+ reflex/.templates/web/vite.config.js,sha256=3aKELQMgA-Xz7Xv81UIS4IdwSW6_sCRQFmvF7Q_RfqQ,983
47
48
  reflex/.templates/web/app/entry.client.js,sha256=2Jv-5SQWHhHmA07BP50f1ew1V-LOsX5VoLtSInnFDj8,264
48
49
  reflex/.templates/web/app/routes.js,sha256=OPPW82B079c4FGq_p5C5OBrkVnTNRFhgG3--WKlJSy0,312
49
50
  reflex/.templates/web/components/reflex/radix_themes_color_mode_provider.js,sha256=dnDHW49imtdalZJQqj7J_u7cj2z8Sve7OlhtOO0FbKE,916
@@ -338,7 +339,7 @@ reflex/constants/compiler.py,sha256=y72_HbyHGyCVv_Xqr3hB3_Nu1p8NA4gUebBqL8cxY6Y,
338
339
  reflex/constants/config.py,sha256=8OIjiBdZZJrRVHsNBheMwopE9AwBFFzau0SXqXKcrPg,1715
339
340
  reflex/constants/custom_components.py,sha256=joJt4CEt1yKy7wsBH6vYo7_QRW0O_fWXrrTf0VY2q14,1317
340
341
  reflex/constants/event.py,sha256=tgoynWQi2L0_Kqc3XhXo7XXL76A-OKhJGHRrNjm7gFw,2885
341
- reflex/constants/installer.py,sha256=wHosh9W2kOE-u65JihEoSCuvD5qdfYIO_MERNgRKCyo,4106
342
+ reflex/constants/installer.py,sha256=0ELKxFmAg-J05bCplIRmY-sCx2rpMqQV29_RWhp0bmg,4134
342
343
  reflex/constants/route.py,sha256=UBjqaAOxiUxlDZCSY4O2JJChKvA4MZrhUU0E5rNvKbM,2682
343
344
  reflex/constants/state.py,sha256=uF_7-M9Gid-P3DjAOq4F1ERplyZhiNccowo_jLrdJrg,323
344
345
  reflex/constants/utils.py,sha256=e1ChEvbHfmE_V2UJvCSUhD_qTVAIhEGPpRJSqdSd6PA,780
@@ -379,7 +380,7 @@ reflex/utils/misc.py,sha256=zbYIl7mI08is9enr851sj7PnDaNeVVvq5jDmQ4wdlCE,2879
379
380
  reflex/utils/net.py,sha256=HEHA8L5g7L9s0fFG4dTiZzB9PFO_0WRrlbMgpZr_GAQ,4093
380
381
  reflex/utils/path_ops.py,sha256=_RS17IQDNr5vcoLLGZx2-z1E5WP-JgDHvaRAOgqrZiU,8154
381
382
  reflex/utils/prerequisites.py,sha256=L2tCFqqiYqygRbQ0JMMBduMdsMkKJLDvzGKZnvI1Enc,66001
382
- reflex/utils/processes.py,sha256=e5V6-eRSh-r7hR34wW5qvowurhDEW9qv-DTOFJl7kO8,16157
383
+ reflex/utils/processes.py,sha256=eYzdfFhhnGnPxWN5USxdoLaYA8m8UEOOuxwxRRtLMW0,16196
383
384
  reflex/utils/pyi_generator.py,sha256=Qm_og4yQcJ3-dwMfGJ2QhPxiFng3lftPJne-dMCC8C0,45532
384
385
  reflex/utils/redir.py,sha256=3JG0cRdfIZnFIBHHN32ynD5cfbUZa7gLRxzrxRGGl5I,1751
385
386
  reflex/utils/registry.py,sha256=DEF7csYQ5VnrZhy6ULVfMlceh7XVH0pks96lIyyThuc,1882
@@ -395,8 +396,8 @@ reflex/vars/number.py,sha256=tO7pnvFaBsedq1HWT4skytnSqHWMluGEhUbjAUMx8XQ,28190
395
396
  reflex/vars/object.py,sha256=BDmeiwG8v97s_BnR1Egq3NxOKVjv9TfnREB3cz0zZtk,17322
396
397
  reflex/vars/sequence.py,sha256=1kBrqihspyjyQ1XDqFPC8OpVGtZs_EVkOdIKBro5ilA,55249
397
398
  scripts/hatch_build.py,sha256=-4pxcLSFmirmujGpQX9UUxjhIC03tQ_fIQwVbHu9kc0,1861
398
- reflex-0.8.0a7.dist-info/METADATA,sha256=XK-wK7ZpvQvGbKnF_mSKw5ohRMG9FJ3HrXNrfslwGGI,12371
399
- reflex-0.8.0a7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
400
- reflex-0.8.0a7.dist-info/entry_points.txt,sha256=Rxt4dXc7MLBNt5CSHTehVPuSe9Xqow4HLX55nD9tQQ0,45
401
- reflex-0.8.0a7.dist-info/licenses/LICENSE,sha256=dw3zLrp9f5ObD7kqS32vWfhcImfO52PMmRqvtxq_YEE,11358
402
- reflex-0.8.0a7.dist-info/RECORD,,
399
+ reflex-0.8.0.post1.dist-info/METADATA,sha256=6HSGjVzE62uNZJc9v-3G4dqo0Qm23_lgD5GsUcQ-yss,12375
400
+ reflex-0.8.0.post1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
401
+ reflex-0.8.0.post1.dist-info/entry_points.txt,sha256=Rxt4dXc7MLBNt5CSHTehVPuSe9Xqow4HLX55nD9tQQ0,45
402
+ reflex-0.8.0.post1.dist-info/licenses/LICENSE,sha256=dw3zLrp9f5ObD7kqS32vWfhcImfO52PMmRqvtxq_YEE,11358
403
+ reflex-0.8.0.post1.dist-info/RECORD,,