Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[馃悶] useClientMount and useClientEffect doesn't seem to work #2329

Closed
alkeryn opened this issue Dec 1, 2022 · 10 comments 路 Fixed by #2365
Closed

[馃悶] useClientMount and useClientEffect doesn't seem to work #2329

alkeryn opened this issue Dec 1, 2022 · 10 comments 路 Fixed by #2365
Assignees
Labels
P4: urgent If Bug - it makes Qwik unstable and affects the majority of users TYPE: bug Something isn't working
Milestone

Comments

@alkeryn
Copy link

alkeryn commented Dec 1, 2022

Which component is affected?

Qwik Runtime

Describe the bug

Hey i tried a bunch of things but even the timer provided example does nothing, the component simply does't update
even console.log() seems to do nothing, any idea ?

Reproduction

qwik 0.14.1

Steps to reproduce

just try the useClientEffect timer example from : https://qwik.builder.io/docs/components/lifecycle/

System Info

System:
    OS: Linux 6.0 Arch Linux
    CPU: (4) x64 Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
    Memory: 1.14 GB / 15.52 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 19.2.0 - /usr/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 8.19.2 - /usr/bin/npm
  Browsers:
    Brave Browser: 102.1.39.111
    Chromium: 108.0.5359.71
    Firefox: 107.0.1

Additional Information

one thing to note is that when i click on the "Blow my mind" button and go back, then they do work, but they fail again when the page is refreshed.

@alkeryn alkeryn added TYPE: bug Something isn't working STATUS-1: needs triage New issue which needs to be triaged labels Dec 1, 2022
@manucorporat manucorporat added this to the 0.15.0 milestone Dec 1, 2022
@manucorporat manucorporat added P4: urgent If Bug - it makes Qwik unstable and affects the majority of users and removed STATUS-1: needs triage New issue which needs to be triaged labels Dec 1, 2022
@manucorporat manucorporat self-assigned this Dec 1, 2022
@zanettin
Copy link
Collaborator

zanettin commented Dec 1, 2022

Hi @alkeryn
Thanks for raising this issue 馃檹 It seems to be related to two other issues which are already open (#1413 and #1955 ).
As a temporary workaround you can change the last line of the example as follow:

from:
return <>{store.count}</>;

to:
return <div>{store.count}</div>; // or any other html tag

@alkeryn
Copy link
Author

alkeryn commented Dec 2, 2022

oh thanks for that tip!
though, not being able to use fragments with it can prove another issue, hope it'll get fixed soon ! :)

@cmbartschat
Copy link
Contributor

Something that isn't super clear from the docs is that if a component mounted on the server, useClientMount$ will not run when the page loads. So from the docs:

Times: exactly once per component instance

I would suggest:

Times: exactly once per component instance, or never if the component was present on the initial page load

For the code example, I think it's worth drawing extra attention to the fact that useServerMount$ and useClientMount$ are mutually exclusive:

import { component$, useStore, useServerMount$, useClientMount$} from '@builder.io/qwik';

export default component$(() => {
  const store = useStore({
    location: '',
  });
  useServerMount$(() => {
    store.location = 'server'
  });
  useClientMount$(() => {
    store.location = 'client' // This will only occur if there is client-side navigation, or the component only started being rendered after the initial page load
  });
  return <>I mounted {store.location} side!</>;
});

Here's a thread on discord where you can see the confusion play out in real time: https://discord.com/channels/842438759945601056/1048474481749921903/1048499061055029329

@manucorporat
Copy link
Contributor

manucorporat commented Dec 3, 2022

Agree that the docs can be better, gonna work on those this week! however things make more sense when you get the right mental model of qwik, code executes in the server and continues in the browser. Calling twice mount would be weird no?

In qwik, you need to really think about pausing and continuing execution in the client, qwik will not execute again what already happened in the server.

@cmbartschat
Copy link
Contributor

Thanks for taking a look! Comparing the wording of these two hooks, the subtleties of what "mount" means in Qwik's mental model is a little muddy.

useClientMount$() - Trigger: component mount
useClientEffect$() - Trigger: component mount and on tracked state changes

This wording would make devs think that useClientMount$ is the same as a useClientEffect$ that only runs once.

@manucorporat
Copy link
Contributor

in a way, they happen once... but at different times, one before render the other after.

@manucorporat
Copy link
Contributor

i am even thinking that removing useServerMount$() and useClientMount$() might be a good idea, only have useMount$() and then use isServer or isBrowser conditionals...

@cmbartschat
Copy link
Contributor

I was kind of thinking the same thing, but will it allow server-only dependencies to be stripped out correctly? Don't want more of: #1477

@manucorporat
Copy link
Contributor

it production yes, but a bit more risky some side effects might be remaining, let's see if we can find a better way to explain useServerMount$() or useClientMount$()! ideas for a PR in the docs?

@cmbartschat
Copy link
Contributor

Sure, I can look at drafting up some clarifications.

reemardelarosa pushed a commit to reemardelarosa/qwik that referenced this issue Dec 8, 2022
mhevery pushed a commit that referenced this issue Dec 22, 2022
* docs: added cheatsheet for anti patterns

* docs:cleanup

* chore: another clickup and spacing update

* chore: Release 0.14.1 (#2264)

* 0.14.1

* 馃悿

* fix: page, endpoint, q-data GET request (#2265)

* chore: release qwik-city 0.0.127 (#2269)

* chore: Add my stock investing website (#2268)

:)

* fix: signal rendering of classes (#2271)

fixes #2245

* docs: fix a typo (#2279)

* docs: Inline causes the clock to not show (#2283)

clock.css is not correctly loaded which causes the clock to not show.
Error: Cannot find module './clock.css?inline' or its corresponding type declarations.

* docs: Tutorial onError should be onRejected (#2284)

When using onError in the IDE as provided in the example it gives the following error:
Property 'onError' does not exist on type 'IntrinsicAttributes & ResourceProps<string[]>'

The solution says it should be onRejected

* fix: not silent error during rendering (#2297)

* fix: correctly handle draggable and spellcheck (#2299)

Co-authored-by: Jeremy Wickersheimer <jwickers@gmail.com>

* docs: right menu for Getting Started & Think Qwik (#2243)

* fix: dev server 302 error (#2300)

* feat: non-serializable response data dev error (#2305)

* docs: fix typo (#2302)

* docs: include vercel edge in the adaptors overview (#2292)

* fix(optimizer): missing args passed to wasm fallback (#2308)

* fix: textarea value rendering in SSR (#2309)

fixes #2235

* feat: better error reporting (#2312)

* fix: render toggle + signal (#2313)

fixes #2311

* feat: Link prefetch by default (#2314)

* fix: useContent menu lookup (#2315)

* docs: updated img-models url in showcase (#2320)

* fix: rendering of sibling component and mandatory key (#2321)

* feat: click-to-source  (#2217) (#2319)



Co-authored-by: Bruno Crosier <bruno.crosier@gmail.com>

* chore: 0.15.0 (#2330)

* fix: client redirect for trailing slash (#2333)

* fix: forceConsistentCasingInFileNames in starters (#2334)

* docs: fix typos and improve explanations (#2332)

* fix: click-to-component (#2335)

* docs: fix some typos and align explanations (#2331)

* release: qwik-city 0.0.128 (#2337)

* docs: fix build.preview (#2341)

* chore: add vite ecosystem scripts (#2349)

* docs: fix typo lifecycle (#2346)

* feat: add URLSearchParams to serializer (#2352)

* refactor: use class prop without casting to any (#2348)


Co-authored-by: langbamit <langbamit@gmail.com>

* feat: add to package.json when present in the ssr dir (#2354)

* docs: Add Qwind starter template to showcase (#2343)

* fix: detect and error on array holes (#2356)

* chore: remove className (#2310)

* fix: textarea vdom patching (#2357)

fixes #2344

* fix: update features (#2363)

* fix: jsx rule with fragment (#2364)

fixes #2177

* feat: Pre-fetch Link data on anchor focus (#2358)

* fix: useClientEffect() in empty components (#2365)

fixes #1955
fixes #2329
fixes #1062
fixes #1413
fixes #1446

* chore: release 0.15.1 (#2366)

* docs: improve styling docs (#2367)

* fix: make array hole test more readable (#2369)

* 0.15.2 (#2371)

* docs: fix typo (#2372)

* docs: removed unnecessary fragments (#2361)

* docs: Add Guide On Using Map Functions In JSX (#2373)

* docs: remove async from component$ overview (#2377)

* feat: add config for dev inspector (#2375)

* docs(qwik-v-react): fix array key consistency in docs (#2383)

Qwik array map in qwik vs. react did not have key even though in rendering portion of docs it says
key is required

* fix(vite): module side effect (#2387)

* feat: detect invalid HTML (#2389)

* docs: link accessibility (#2386)

* feat: standardize params/query api (#2385)

Co-Authored-By: Tran Thien Khiem <20198928+tuoitrevohoc@users.noreply.github.com>

* docs(contributing): Add install note for wasm-pack (#2390)

To avoid running into unexpected `wasm-pack` failures when doing full build, adds note to Contributing docs about installation of `wasm-pack`, linking to site showing installation command for each platform.

* docs: update anti pattern to best practice

Co-authored-by: Manu MA <manu.mtza@gmail.com>
Co-authored-by: Adam Bradley <adamdbradley@users.noreply.github.com>
Co-authored-by: Shih-Min Lee <ssmlee04@gmail.com>
Co-authored-by: Tejas Kumar <tejas+lol@tejas.qa>
Co-authored-by: Bryan Hannes <31400961+bryanhannes@users.noreply.github.com>
Co-authored-by: Jeremy Wickersheimer <jwickers@gmail.com>
Co-authored-by: Forresst <forresst17@gmail.com>
Co-authored-by: Mhmdrz_a <mr.ala72@gmail.com>
Co-authored-by: Shai Reznik <shairez@users.noreply.github.com>
Co-authored-by: Bruno Crosier <bruno.crosier@gmail.com>
Co-authored-by: Alberto Mijares <almilo@users.noreply.github.com>
Co-authored-by: Uther Pally <43192714+langbamit@users.noreply.github.com>
Co-authored-by: langbamit <langbamit@gmail.com>
Co-authored-by: Wim Holvoet <holvoetwim@gmail.com>
Co-authored-by: prototypa <54446028+prototypa@users.noreply.github.com>
Co-authored-by: Glenn Becker <nnelgxorz@gmail.com>
Co-authored-by: Wout Mertens <Wout.Mertens@gmail.com>
Co-authored-by: Saikat Das <saikatdas0790@gmail.com>
Co-authored-by: Sai Srikar Dumpeti <80447788+the-r3aper7@users.noreply.github.com>
Co-authored-by: Justin Scopelleti <38704268+Kesmek@users.noreply.github.com>
Co-authored-by: roman zanettin <zanettin@users.noreply.github.com>
Co-authored-by: jweb89 <62513031+jweb89@users.noreply.github.com>
Co-authored-by: Tran Thien Khiem <20198928+tuoitrevohoc@users.noreply.github.com>
Co-authored-by: machineloop <3682072+machineloop@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4: urgent If Bug - it makes Qwik unstable and affects the majority of users TYPE: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants