rwsdk 0.1.20 → 0.1.21

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.
@@ -1 +1,2 @@
1
+ import "./types/worker";
1
2
  export * from "../lib/auth";
@@ -1 +1,2 @@
1
+ import "./types/worker";
1
2
  export * from "../lib/auth";
@@ -1,3 +1,4 @@
1
+ import "./types/client";
1
2
  export * from "../client";
2
3
  export * from "../register/client";
3
4
  export * from "../lib/streams/consumeEventStream";
@@ -1,3 +1,4 @@
1
+ import "./types/client";
1
2
  export * from "../client";
2
3
  export * from "../register/client";
3
4
  export * from "../lib/streams/consumeEventStream";
@@ -1 +1,2 @@
1
+ import "./types/ssr";
1
2
  export * from "../lib/streams/consumeEventStream";
@@ -1 +1,2 @@
1
+ import "./types/ssr";
1
2
  export * from "../lib/streams/consumeEventStream";
@@ -1,2 +1,3 @@
1
+ import "./types/shared";
1
2
  export * from "../lib/router";
2
3
  export * from "../lib/links";
@@ -1,2 +1,3 @@
1
+ import "./types/shared";
1
2
  export * from "../lib/router";
2
3
  export * from "../lib/links";
@@ -1 +1,2 @@
1
+ import "./types/ssr";
1
2
  export * from "../register/ssr";
@@ -1 +1,2 @@
1
+ import "./types/ssr";
1
2
  export * from "../register/ssr";
@@ -0,0 +1 @@
1
+ import "./shared";
@@ -0,0 +1 @@
1
+ import "./shared";
@@ -0,0 +1,7 @@
1
+ interface ImportMeta {
2
+ readonly env: ImportMetaEnv;
3
+ }
4
+ interface ImportMetaEnv {
5
+ readonly DEV: boolean;
6
+ readonly VITE_IS_DEV_SERVER: string;
7
+ }
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ import "./shared";
@@ -0,0 +1 @@
1
+ import "./shared";
@@ -0,0 +1 @@
1
+ import "./shared";
@@ -0,0 +1 @@
1
+ import "./shared";
@@ -1,3 +1,4 @@
1
+ import "./types/worker";
1
2
  export * from "../register/worker";
2
3
  export * from "../worker";
3
4
  export * from "../error";
@@ -1,3 +1,4 @@
1
+ import "./types/worker";
1
2
  export * from "../register/worker";
2
3
  export * from "../worker";
3
4
  export * from "../error";
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import memoize from "lodash/memoize";
3
3
  export const loadModule = memoize(async (id) => {
4
- if (import.meta.env.DEV && !process.env.PREVIEW) {
4
+ if (import.meta.env.VITE_IS_DEV_SERVER) {
5
5
  return await import(/* @vite-ignore */ id);
6
6
  }
7
7
  else {
@@ -1,8 +1,9 @@
1
1
  import { ErrorResponse } from "../../error";
2
- import { IS_DEV } from "../../constants";
3
2
  import { env } from "cloudflare:workers";
4
3
  const AUTH_SECRET_KEY = env.AUTH_SECRET_KEY ??
5
- (IS_DEV ? "development-secret-key-do-not-use-in-production" : undefined);
4
+ (import.meta.env.VITE_IS_DEV_SERVER
5
+ ? "development-secret-key-do-not-use-in-production"
6
+ : undefined);
6
7
  if (AUTH_SECRET_KEY === "") {
7
8
  console.warn("AUTH_SECRET_KEY is set but empty. Please provide a non-empty secret key for session store security.");
8
9
  }
@@ -1,6 +1,5 @@
1
1
  "use client";
2
2
  import { useRef, useCallback } from "react";
3
- import { IS_DEV } from "../../constants";
4
3
  export function useTurnstile(siteKey) {
5
4
  const containerRef = useRef(null);
6
5
  const resolverRef = useRef(Promise.withResolvers());
@@ -10,7 +9,9 @@ export function useTurnstile(siteKey) {
10
9
  containerRef.current &&
11
10
  window.turnstile) {
12
11
  widgetIdRef.current = window.turnstile.render(containerRef.current, {
13
- sitekey: IS_DEV ? "1x00000000000000000000AA" : siteKey,
12
+ sitekey: import.meta.env.VITE_IS_DEV_SERVER
13
+ ? "1x00000000000000000000AA"
14
+ : siteKey,
14
15
  callback: (token) => resolverRef.current.resolve(token),
15
16
  });
16
17
  }
@@ -1,6 +1,5 @@
1
1
  import { registerServerReference as baseRegisterServerReference, registerClientReference as baseRegisterClientReference, decodeReply, } from "react-server-dom-webpack/server.edge";
2
2
  import { getServerModuleExport } from "../imports/worker.js";
3
- import { IS_DEV } from "../constants";
4
3
  export function registerServerReference(action, id, name) {
5
4
  if (typeof action !== "function") {
6
5
  return action;
@@ -31,7 +30,7 @@ export async function rscActionHandler(req) {
31
30
  : await req.text();
32
31
  const args = (await decodeReply(data, null));
33
32
  const actionId = url.searchParams.get("__rsc_action_id");
34
- if (IS_DEV && actionId === "__rsc_hot_update") {
33
+ if (import.meta.env.VITE_IS_DEV_SERVER && actionId === "__rsc_hot_update") {
35
34
  return null;
36
35
  }
37
36
  const action = await getServerModuleExport(actionId);
@@ -7,7 +7,6 @@ import { ErrorResponse } from "./error";
7
7
  import { getRequestInfo, runWithRequestInfo, runWithRequestInfoOverrides, } from "./requestInfo/worker";
8
8
  import { defineRoutes } from "./lib/router";
9
9
  import { generateNonce } from "./lib/utils";
10
- import { IS_DEV } from "./constants";
11
10
  import { ssrWebpackRequire } from "./imports/worker";
12
11
  export const defineApp = (routes) => {
13
12
  return {
@@ -22,7 +21,8 @@ export const defineApp = (routes) => {
22
21
  url.pathname = url.pathname.slice("/assets/".length);
23
22
  return env.ASSETS.fetch(new Request(url.toString(), request));
24
23
  }
25
- else if (IS_DEV && request.url.includes("/__vite_preamble__")) {
24
+ else if (import.meta.env.VITE_IS_DEV_SERVER &&
25
+ request.url.includes("/__vite_preamble__")) {
26
26
  return new Response('import RefreshRuntime from "/@react-refresh"; RefreshRuntime.injectIntoGlobalHook(window); window.$RefreshReg$ = () => {}; window.$RefreshSig$ = () => (type) => type; window.__vite_plugin_react_preamble_installed__ = true;', {
27
27
  headers: {
28
28
  "content-type": "text/javascript",
@@ -76,7 +76,7 @@ export const defineApp = (routes) => {
76
76
  };
77
77
  const renderPage = async (requestInfo, Page, onError) => {
78
78
  if (isClientReference(requestInfo.rw.Document)) {
79
- if (IS_DEV) {
79
+ if (import.meta.env.DEV) {
80
80
  console.error("Document cannot be a client component");
81
81
  }
82
82
  return new Response(null, {
@@ -0,0 +1,9 @@
1
+ import { Plugin } from "vite";
2
+ declare global {
3
+ namespace NodeJS {
4
+ interface ProcessEnv {
5
+ VITE_IS_DEV_SERVER: string;
6
+ }
7
+ }
8
+ }
9
+ export declare const devServerConstantPlugin: () => Plugin;
@@ -0,0 +1,11 @@
1
+ export const devServerConstantPlugin = () => {
2
+ return {
3
+ name: "rwsdk:dev-server-constant",
4
+ config(_, { command, isPreview }) {
5
+ if (command === "serve" && isPreview) {
6
+ // context(justinvdm, 21 Jul 2025): Vite forwards this as `import.meta.env.DEV_IS_DEV_SERVER`
7
+ process.env.VITE_IS_DEV_SERVER = "1";
8
+ }
9
+ },
10
+ };
11
+ };
@@ -1,6 +1,7 @@
1
1
  import { resolve } from "node:path";
2
2
  import { unstable_readConfig } from "wrangler";
3
3
  import { cloudflare } from "@cloudflare/vite-plugin";
4
+ import { devServerConstantPlugin } from "./devServerConstant.mjs";
4
5
  import { hasOwnCloudflareVitePlugin } from "./hasOwnCloudflareVitePlugin.mjs";
5
6
  import reactPlugin from "@vitejs/plugin-react";
6
7
  import tsconfigPaths from "vite-tsconfig-paths";
@@ -54,6 +55,7 @@ export const redwoodPlugin = async (options = {}) => {
54
55
  }
55
56
  return [
56
57
  devServerTimingPlugin(),
58
+ devServerConstantPlugin(),
57
59
  configPlugin({
58
60
  silent: options.silent ?? false,
59
61
  projectRootDir,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rwsdk",
3
- "version": "0.1.20",
3
+ "version": "0.1.21",
4
4
  "description": "Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime",
5
5
  "type": "module",
6
6
  "bin": {