BREAKING: disable runtime JS by default (#55)

This commit is contained in:
Luca Casonato
2021-09-25 11:05:49 +02:00
committed by GitHub
parent f44f1950dc
commit 0fbc9e816a
7 changed files with 24 additions and 14 deletions
+3 -1
View File
@@ -2,7 +2,7 @@
import { RoundedButton } from "../components/Button.tsx"; import { RoundedButton } from "../components/Button.tsx";
import { IconMinus, IconPlus } from "../components/Icons.tsx"; import { IconMinus, IconPlus } from "../components/Icons.tsx";
import { h, IS_BROWSER, tw, useState } from "../deps.ts"; import { h, IS_BROWSER, PageConfig, tw, useState } from "../deps.ts";
export default function Home() { export default function Home() {
return ( return (
@@ -43,3 +43,5 @@ function Counter() {
</div> </div>
); );
} }
export const config: PageConfig = { runtimeJS: true };
+10 -6
View File
@@ -19,13 +19,17 @@ export interface PageProps {
export interface PageConfig { export interface PageConfig {
/** /**
* Setting this flag to `false` disables all client side runtime JS. This * By default, runtime JS is disabled. This means that interactivity on the
* means that all interactivity on the client that depends on Preact or other * client that depends on Preact or other JS code will not function.
* JS code will not function. This option is set to `true` (runtime javascript
* is enabled) by default.
* *
* It is recommended to disable runtime JavaScript for static pages that do * Runtime JS can be enabled by setting `runtimeJS` to `true`.
* not require interactivity, like marketing or blog pages. *
* It is recommended to keep runtime JavaScript disabled for static pages that
* do not require interactivity, like marketing or blog pages.
*
* Note that the runtime JS feature will likely be overhauled in the future to
* provide more granular control over which components need to be hydrated on
* the client.
*/ */
runtimeJS?: boolean; runtimeJS?: boolean;
} }
+1 -1
View File
@@ -59,7 +59,7 @@ export class ServerContext {
name, name,
component, component,
handler, handler,
runtimeJS: config?.runtimeJS ?? true, runtimeJS: config?.runtimeJS ?? false,
}; };
pages.push(page); pages.push(page);
} else if ( } else if (
+3 -1
View File
@@ -1,6 +1,6 @@
/** @jsx h */ /** @jsx h */
import { h } from "../deps.ts"; import { h, PageConfig } from "../deps.ts";
interface Props { interface Props {
params: Record<string, string | string[]>; params: Record<string, string | string[]>;
@@ -9,3 +9,5 @@ interface Props {
export default function Greet(props: Props) { export default function Greet(props: Props) {
return <div>Hello {props.params.name}</div>; return <div>Hello {props.params.name}</div>;
} }
export const config: PageConfig = { runtimeJS: true };
+3 -1
View File
@@ -1,6 +1,6 @@
/** @jsx h */ /** @jsx h */
import { h, IS_BROWSER, useData } from "../deps.ts"; import { h, IS_BROWSER, PageConfig, useData } from "../deps.ts";
export default function Home() { export default function Home() {
const message = useData("home", (key) => { const message = useData("home", (key) => {
@@ -15,3 +15,5 @@ export default function Home() {
</div> </div>
); );
} }
export const config: PageConfig = { runtimeJS: true };
+3 -1
View File
@@ -1,7 +1,9 @@
/** @jsx h */ /** @jsx h */
import { h, PageProps } from "../../deps.ts"; import { h, PageConfig, PageProps } from "../../deps.ts";
export default function Home(props: PageProps) { export default function Home(props: PageProps) {
return <div>{JSON.stringify(props)}</div>; return <div>{JSON.stringify(props)}</div>;
} }
export const config: PageConfig = { runtimeJS: true };
+1 -3
View File
@@ -1,9 +1,7 @@
/** @jsx h */ /** @jsx h */
import { h, PageConfig } from "../deps.ts"; import { h } from "../deps.ts";
export default function StaticPage() { export default function StaticPage() {
return <p>This is a static page.</p>; return <p>This is a static page.</p>;
} }
export const config: PageConfig = { runtimeJS: false };