Skip to content

Commit 403007e

Browse files
Chris LorenzoMilo
authored andcommitted
add universal support
1 parent eee8096 commit 403007e

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ There are 3 modes available:
1212
- DOM: The classic SPA generation mechanism
1313
- SSR: The server side generation mechanism
1414
- HYDRATION: The client side generation for hydration
15+
- UNIVERSAL: The client side generation for universal (custom renderer)
1516

1617
## Getting up and running
1718

packages/solid-repl/src/components/repl.tsx

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const compileMode = {
1919
SSR: { generate: 'ssr', hydratable: true },
2020
DOM: { generate: 'dom', hydratable: false },
2121
HYDRATABLE: { generate: 'dom', hydratable: true },
22+
UNIVERSAL: { generate: 'universal', hydratable: false, moduleName: "solid-universal-module" as string },
2223
} as const;
2324

2425
const findExtension = (str: string): '.tsx' | '.jsx' => {
@@ -44,6 +45,7 @@ export const Repl: ReplProps = (props) => {
4445

4546
const [error, setError] = createSignal('');
4647
const [output, setOutput] = createSignal('');
48+
const [universalModuleName, setUniversalModuleName] = createSignal('solid-universal-module');
4749
const [mode, setMode] = createSignal<(typeof compileMode)[keyof typeof compileMode]>(compileMode.DOM);
4850

4951
const userTabs = () => props.tabs.filter((tab) => tab.name != 'import_map.json');
@@ -166,6 +168,13 @@ export const Repl: ReplProps = (props) => {
166168
}, 250);
167169

168170
const compile = () => {
171+
let compileOpts = mode();
172+
if (compileOpts === compileMode.UNIVERSAL) {
173+
compileOpts = { generate: 'universal',
174+
hydratable: false,
175+
moduleName: universalModuleName()
176+
}
177+
}
169178
applyCompilation(
170179
outputTab() == 0
171180
? {
@@ -175,7 +184,7 @@ export const Repl: ReplProps = (props) => {
175184
: {
176185
event: 'BABEL',
177186
tab: unwrap(props.tabs.find((tab) => tab.name == props.current)),
178-
compileOpts: mode(),
187+
compileOpts,
179188
},
180189
);
181190
};
@@ -403,7 +412,6 @@ export const Repl: ReplProps = (props) => {
403412
class="-mb-0.5 w-full py-2"
404413
onClick={() => {
405414
setOutputTab(1);
406-
setMode(compileMode.DOM);
407415
}}
408416
>
409417
Output
@@ -464,6 +472,28 @@ export const Repl: ReplProps = (props) => {
464472
/>
465473
<span>Client side rendering with hydration</span>
466474
</label>
475+
476+
<label class="mr-auto block cursor-pointer space-x-2">
477+
<input
478+
checked={mode() === compileMode.UNIVERSAL}
479+
value="UNIVERSAL"
480+
class="text-brand-default"
481+
onChange={[setMode, compileMode.UNIVERSAL]}
482+
type="radio"
483+
name="dom"
484+
/>
485+
<span>Universal Rendering & moduleName:</span>
486+
<input
487+
onFocus={[setMode, compileMode.UNIVERSAL]}
488+
onInput={(e) => {
489+
setUniversalModuleName(e.target.value);
490+
}}
491+
class="p-2.5"
492+
type="text"
493+
value={universalModuleName()}
494+
name="moduleName"
495+
/>
496+
</label>
467497
</div>
468498
</div>
469499
</section>

0 commit comments

Comments
 (0)