@@ -54,15 +54,21 @@ function compileRuntime(source, compiler, generate) {
5454// prod (signals' `DEV` export is undefined) and the first click throws. Every
5555// flag the runtime packages gate on must be listed in BOTH places: a flag the
5656// define misses is a ReferenceError at first use.
57- const workspaceSourceRoots = [ "solid" , "web" , "signals" ] . map (
57+ const workspaceSourceRoots = [ "solid" , "web" , "signals" , "universal" ] . map (
5858 name => path . join ( repoRoot , "packages" , name , "src" ) + path . sep
5959) ;
6060
6161async function loadRuntimeModule ( code , generate ) {
6262 const aliases = new Map ( [
6363 [
6464 "@solidjs/web" ,
65- path . join ( repoRoot , "packages/web/src" , generate === "ssr" ? "index.server.ts" : "index.ts" )
65+ generate === "universal"
66+ ? path . join ( repoRoot , "packages/universal/test/custom.js" )
67+ : path . join (
68+ repoRoot ,
69+ "packages/web/src" ,
70+ generate === "ssr" ? "index.server.ts" : "index.ts"
71+ )
6672 ] ,
6773 [ "solid-js" , path . join ( repoRoot , "packages/solid/src/index.ts" ) ] ,
6874 // The web runtime reaches solid-js's seams through this subpath (#3470).
@@ -99,6 +105,11 @@ async function loadRuntimeModule(code, generate) {
99105 path : aliases . get ( args . path )
100106 } )
101107 ) ;
108+ esbuild . onLoad ( { filter : / \/ u n i v e r s a l \/ t e s t \/ c u s t o m \. j s $ / } , args => ( {
109+ contents : fs . readFileSync ( args . path , "utf8" ) + '\nexport * from "solid-js";' ,
110+ loader : "js" ,
111+ resolveDir : path . dirname ( args . path )
112+ } ) ) ;
102113 esbuild . onLoad ( { filter : / \. t s $ / } , args => {
103114 if ( ! workspaceSourceRoots . some ( root => args . path . startsWith ( root ) ) ) return ;
104115 return {
@@ -215,7 +226,11 @@ describe.each(["babel", "oxc"])("%s TSRX runtime behavior", compiler => {
215226 dispose ( ) ;
216227 } ) ;
217228
218- test ( "passes For and Errored accessor bindings through as authored" , async ( ) => {
229+ test . each (
230+ [ "dom" , "universal" ] . flatMap ( mode =>
231+ [ " row.id" , "(row.id)" , "(/* key */ ((row.id)))" ] . map ( key => [ mode , key ] )
232+ )
233+ ) ( "passes For and Errored accessor bindings through in %s with key%s" , async ( mode , key ) => {
219234 // #3474: the bindings are the accessors Solid hands out. `row()` and `i()`
220235 // read live under a custom key, `err()` is the ErrorAccessor.
221236 const source = `
@@ -236,7 +251,7 @@ describe.each(["babel", "oxc"])("%s TSRX runtime behavior", compiler => {
236251 export function App() @{
237252 <section>
238253 <ul>
239- @for (const row of rows(); index i; key row.id ) {
254+ @for (const row of rows(); index i; key${ key } ) {
240255 const snapshot = row;
241256 <li data-id={snapshot().id}>{i()}:{row().label ?? row().id}:{row().extra}</li>
242257 }
@@ -258,7 +273,7 @@ describe.each(["babel", "oxc"])("%s TSRX runtime behavior", compiler => {
258273 flush();
259274 }
260275 ` ;
261- const runtime = await loadRuntimeModule ( compileRuntime ( source , compiler , "dom" ) , "dom" ) ;
276+ const runtime = await loadRuntimeModule ( compileRuntime ( source , compiler , mode ) , mode ) ;
262277 const root = document . createElement ( "div" ) ;
263278 const dispose = runtime . mount ( root ) ;
264279
@@ -281,6 +296,54 @@ describe.each(["babel", "oxc"])("%s TSRX runtime behavior", compiler => {
281296 dispose ( ) ;
282297 } ) ;
283298
299+ test . each (
300+ [ "dom" , "ssr" , "universal" ] . flatMap ( mode =>
301+ [ "key item.id" , "index i" , "index i; key item.id" ] . map ( annotation => [ mode , annotation ] )
302+ )
303+ ) ( "renders a statement-position annotated loop in %s with %s" , async ( mode , annotation ) => {
304+ const source = `
305+ import { createSignal, flush } from "solid-js";
306+ import { ${ mode === "ssr" ? "renderToString" : "render" } } from "@solidjs/web";
307+ const [items, setItems] = createSignal([
308+ { id: 1, label: "one" }, { id: 2, label: "two" }
309+ ]);
310+ export function App() @{
311+ @for (const item of items(); ${ annotation } ) {
312+ <span data-id={item().id}>{item().label}</span>
313+ }
314+ }
315+ export function run(target) {
316+ return ${ mode === "ssr" ? "renderToString(App)" : "render(App, target)" } ;
317+ }
318+ export function replaceItems(next) {
319+ setItems(next);
320+ flush();
321+ }
322+ ` ;
323+ const output = compileRuntime ( source , compiler , mode ) ;
324+ expect ( output ) . not . toMatch ( / _ _ t s r x / ) ;
325+ const runtime = await loadRuntimeModule ( output , mode ) ;
326+ if ( mode === "ssr" ) {
327+ expect ( runtime . run ( ) ) . toBe ( '<span data-id="1">one</span><span data-id="2">two</span>' ) ;
328+ return ;
329+ }
330+ const root = document . createElement ( "div" ) ;
331+ const dispose = runtime . run ( root ) ;
332+ expect ( root . textContent ) . toBe ( "onetwo" ) ;
333+ const retained = root . querySelector ( '[data-id="2"]' ) ;
334+ runtime . replaceItems ( [
335+ { id : 2 , label : "TWO" } ,
336+ { id : 3 , label : "three" }
337+ ] ) ;
338+ expect ( root . textContent ) . toBe ( "TWOthree" ) ;
339+ if ( annotation . includes ( "key" ) ) {
340+ expect ( root . querySelector ( '[data-id="2"]' ) ) . toBe ( retained ) ;
341+ }
342+ runtime . replaceItems ( [ ] ) ;
343+ expect ( root . textContent ) . toBe ( "" ) ;
344+ dispose ( ) ;
345+ } ) ;
346+
284347 test ( "rejects destructuring where Solid passes an accessor" , ( ) => {
285348 const cases = [
286349 [
@@ -348,22 +411,25 @@ describe.each(["babel", "oxc"])("%s TSRX runtime behavior", compiler => {
348411 dispose ( ) ;
349412 } ) ;
350413
351- test ( "renders SSR branches, keyed lists, and empty fallbacks" , async ( ) => {
352- const source = readRuntimeFixture ( "ssr" ) ;
353- const runtime = await loadRuntimeModule ( compileRuntime ( source , compiler , "ssr" ) , "ssr" ) ;
354-
355- expect (
356- runtime . renderPage ( {
357- show : true ,
358- items : [
359- { id : 1 , label : "one" } ,
360- { id : 2 , label : "two" }
361- ]
362- } )
363- ) . toBe ( "<main><ul><li>one</li><li>two</li></ul></main>" ) ;
364- expect ( runtime . renderPage ( { show : true , items : [ ] } ) ) . toBe (
365- "<main><ul><li>empty</li></ul></main>"
366- ) ;
367- expect ( runtime . renderPage ( { show : false , items : [ ] } ) ) . toBe ( "<main><p>hidden</p></main>" ) ;
368- } ) ;
414+ test . each ( [ " item.id" , "(item.id)" , "(/* key */ ((item.id)))" ] ) (
415+ "renders SSR branches, keyed lists, and empty fallbacks with key%s" ,
416+ async key => {
417+ const source = readRuntimeFixture ( "ssr" ) . replace ( "key item.id" , `key${ key } ` ) ;
418+ const runtime = await loadRuntimeModule ( compileRuntime ( source , compiler , "ssr" ) , "ssr" ) ;
419+
420+ expect (
421+ runtime . renderPage ( {
422+ show : true ,
423+ items : [
424+ { id : 1 , label : "one" } ,
425+ { id : 2 , label : "two" }
426+ ]
427+ } )
428+ ) . toBe ( "<main><ul><li>one</li><li>two</li></ul></main>" ) ;
429+ expect ( runtime . renderPage ( { show : true , items : [ ] } ) ) . toBe (
430+ "<main><ul><li>empty</li></ul></main>"
431+ ) ;
432+ expect ( runtime . renderPage ( { show : false , items : [ ] } ) ) . toBe ( "<main><p>hidden</p></main>" ) ;
433+ }
434+ ) ;
369435} ) ;
0 commit comments