Skip to content

Commit feb425e

Browse files
test(compiler): mirror __OBSERVE__ in the TSRX runtime harness; fail on any unreplaced flag
The runtime bundle defines __DEV__ and replaces "_SOLID_DEV_" but knew nothing of the new __OBSERVE__ / "_SOLID_OBSERVE_" pair: every runtime test threw ReferenceError: __OBSERVE__ is not defined. Solid CI does not run these (native binary), so this would have surfaced only in the Compiler-binaries workflow the release gates on — the same shape that blocked rc.7. Add the flag to both lists, and make the class of mistake impossible to miss: after bundling, scan for any surviving __FLAG__ identifier or "_SOLID_FLAG_" literal and fail naming it. Co-authored-by: Cursor <[email protected]>
1 parent 1807f7f commit feb425e

1 file changed

Lines changed: 33 additions & 6 deletions

File tree

‎packages/compiler/__tests__/tsrx-runtime.test.js‎

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,15 @@ function compileRuntime(source, compiler, generate) {
4545
: compileOxc(source, `${generate}-runtime`, options, ".tsrx");
4646
}
4747

48-
// The runtime bundle is prod: `__DEV__` (signals) is a `define` below, but
49-
// solid-js / @solidjs/web gate dev code on the `"_SOLID_DEV_"` string literal
50-
// that rollup's replace plugin rewrites at build time — esbuild `define` can't
48+
// The runtime bundle is prod: `__DEV__` / `__OBSERVE__` (signals) are
49+
// `define`s below, but solid-js / @solidjs/web gate dev code and observe
50+
// wiring on the `"_SOLID_DEV_"` / `"_SOLID_OBSERVE_"` string literals that
51+
// rollup's replace plugin rewrites at build time — esbuild `define` can't
5152
// reach a string literal, so a source-text replace mirrors the build here.
5253
// Without it the bundle is half dev (web's dev event wrapper runs) and half
53-
// prod (signals' `DEV` export is undefined) and the first click throws.
54+
// prod (signals' `DEV` export is undefined) and the first click throws. Every
55+
// flag the runtime packages gate on must be listed in BOTH places: a flag the
56+
// define misses is a ReferenceError at first use.
5457
const workspaceSourceRoots = ["solid", "web", "signals"].map(
5558
name => path.join(repoRoot, "packages", name, "src") + path.sep
5659
);
@@ -77,6 +80,7 @@ async function loadRuntimeModule(code, generate) {
7780
write: false,
7881
define: {
7982
__DEV__: "false",
83+
__OBSERVE__: "false",
8084
__TEST__: "false"
8185
},
8286
plugins: [
@@ -89,7 +93,10 @@ async function loadRuntimeModule(code, generate) {
8993
esbuild.onLoad({ filter: /\.ts$/ }, args => {
9094
if (!workspaceSourceRoots.some(root => args.path.startsWith(root))) return;
9195
return {
92-
contents: fs.readFileSync(args.path, "utf8").replaceAll('"_SOLID_DEV_"', "false"),
96+
contents: fs
97+
.readFileSync(args.path, "utf8")
98+
.replaceAll('"_SOLID_DEV_"', "false")
99+
.replaceAll('"_SOLID_OBSERVE_"', "false"),
93100
loader: "ts"
94101
};
95102
});
@@ -98,12 +105,32 @@ async function loadRuntimeModule(code, generate) {
98105
]
99106
});
100107

108+
const bundle = result.outputFiles[0].text;
109+
110+
// A build flag neither list above knows about survives into the bundle and
111+
// fails at first use as a ReferenceError deep in the runtime (rc.7's
112+
// `__OBSERVE__`). Name it here instead. `__PURE__` / `__NO_SIDE_EFFECTS__`
113+
// are annotations esbuild keeps, not flags.
114+
const unreplaced = [
115+
...new Set(
116+
[...bundle.matchAll(/\b__[A-Z]+__\b|"_SOLID_[A-Z]+_"/g)]
117+
.map(m => m[0])
118+
.filter(flag => flag !== "__PURE__" && flag !== "__NO_SIDE_EFFECTS__")
119+
)
120+
];
121+
if (unreplaced.length) {
122+
throw new Error(
123+
`Runtime bundle still carries build flag(s) ${unreplaced.join(", ")}: add each to ` +
124+
"the esbuild `define` (identifier form) and the onLoad replace (string form) above."
125+
);
126+
}
127+
101128
// Each generated module bundles an isolated runtime copy. Reset the dev
102129
// duplicate-instance sentinel so running Babel and Oxc side by side does
103130
// not produce a false warning.
104131
delete globalThis.Solid$$;
105132
const runtimeModule = { exports: {} };
106-
new Function("require", "module", "exports", result.outputFiles[0].text)(
133+
new Function("require", "module", "exports", bundle)(
107134
require,
108135
runtimeModule,
109136
runtimeModule.exports

0 commit comments

Comments
 (0)