denoland / fresh

The next-gen web framework.
https://fresh.deno.dev
MIT License
12.16k stars 621 forks source link

IOs 12.x.x, events handling not works. #1834

Closed danilovmy closed 11 months ago

danilovmy commented 11 months ago

Not works:

function changeUsername(event) {
        alert('Stupid Boy');
};
...
<button class="bg-grey-light border rounded p-4 shadow-md" onclick={changeUsername}>Log in</button>

Works:

<button class="bg-grey-light border rounded p-4 shadow-md" onclick="alert('Stupid Boy');">Log in</button>
marvinhagemeister commented 11 months ago

@danilovmy is this code inside an island?

danilovmy commented 11 months ago

page:

// index.html
import { signal } from "@preact/signals";
import Hello from "../islands/hello.tsx";
import Layout from "../components/layout.tsx"

const username = signal('');

export default function Home(props) {
    return (
        <Layout>
            <Hello username={username} class="container"/>
        </Layout>
    );
}

island:

import UsernameForm from "../components/usernameform.tsx";

function changeUsername(event) {
    event.preventDefault();
    alert('hello');
};

export default function Hello({username}) {
    return (
        <div class="p-4 mx-auto max-w-screen-md">
            <UsernameForm username={username} onclick={changeUsername} />
        </div>
    );
};

component

export default function UsernameForm({username, onclick}) {
    return (
        <form>
            <input type="text" class="" name="username" value={ username.value || 'Anonym' }/>
            <button class="bg-grey-light border rounded p-4 shadow-md" onclick={onclick}>Log in</button>
        </form>
    );
};

We can throw away Layout, or we can move code from component to island, don't matter. The counter on the fresh homepage not works too. IOs 12.5.5, Safary or Chrome. I check it, for example, with VueJs3: simply counter on the page works.

If it helps: in debug mode before fresh-app starts i see the error:

SyntaxError: Unexpected token ‘?’
promiseReactionJob

I remember, on Fresh 1.4 it probably all, ok, but i am not shure. Sorry.

marvinhagemeister commented 11 months ago

Looks like it stumbles on some newer JS features. With the upcoming build.target option you can set esbuild's target option to downtranspile code to the required browser target. It will be released as part of the next Fresh version. See https://github.com/denoland/fresh/pull/1837