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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐞] Elements processed out of order with no SSR #3966

Closed
ulic75 opened this issue Apr 28, 2023 · 7 comments
Closed

[🐞] Elements processed out of order with no SSR #3966

ulic75 opened this issue Apr 28, 2023 · 7 comments
Labels
STATUS-3: works as expected This issue is closed because the behavior is correct and expected TYPE: bug Something isn't working

Comments

@ulic75
Copy link
Contributor

ulic75 commented Apr 28, 2023

Which component is affected?

Qwik Runtime

Describe the bug

When I run pnpm vite and view the page as defined below I see 2, 3, 1 printed to the browser console. However when I run pnpm vite --mode ssr and view the page I see 1, 2, 3 printed to the server console.

If you add additional children it just trickles down, the FIRST is always executed LAST in non-ssr. In the DOM it appears in the correct order in both scenerios. This makes component testing challenging when you are expecting a precise ordering.

import { component$ } from '@builder.io/qwik';

const Child = component$((props: { order: string }) => {
  console.log(props.order);
  return <div>{props.order}</div>;
});

export default component$(() => {
  return (
    <div class="test">
          <Child order="1" />
          <Child order="2" />
          <Child order="3" />
    </div>
  );
});

Reproduction

https://stackblitz.com/edit/qwik-starter-tvnpeu?file=src/root.tsx

Steps to reproduce

  1. Allow the blitz to run as default
  2. See 1,2,3 printed to the server console
  3. Ctrl-C to kill the server
  4. Start server in non-ssr with npm run start-nossr
  5. See 2,3,1 printed to the browser console

System Info

System:
    OS: macOS 13.1
    CPU: (8) x64 Intel Xeon Processor (Cascadelake)
    Memory: 18.87 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.16.0 - ~/.asdf/installs/nodejs/18.16.0/bin/node
    npm: 9.5.1 - ~/.asdf/plugins/nodejs/shims/npm
  Browsers:
    Firefox: 110.0.1
    Safari: 16.2
  npmPackages:
    @builder.io/qwik: 0.105.0 => 0.105.0 
    @builder.io/qwik-city: ~0.104.0 => 0.104.0 
    undici: 5.22.0 => 5.22.0 
    vite: 4.3.3 => 4.3.3

Additional Information

No response

@ulic75 ulic75 added TYPE: bug Something isn't working STATUS-1: needs triage New issue which needs to be triaged labels Apr 28, 2023
@stackblitz
Copy link

stackblitz bot commented Apr 28, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@ulic75 ulic75 changed the title [🐞] Elements processed out of order with not SSR [🐞] Elements processed out of order with no SSR May 1, 2023
@ulic75
Copy link
Contributor Author

ulic75 commented Oct 26, 2023

Related to #4757

@wmertens
Copy link
Member

Here's a playground demonstrating the issue.

Interestingly, the second time you render on the client it does do it in order.

However, I don't think this will get fixed. There's no guarantees on rendering order, and implementing such guarantees takes effort, continued maintenance, and might impact performance.

@mhevery what's your take on this?

@mhevery
Copy link
Contributor

mhevery commented Oct 31, 2023

This has to do in dev mode we lazy load code, which means there is a promise that causes a delay in rendering. I don't think this is something we can fix without a perf penalty, so I would say it works as intended.

I am tempted to close issue as working as intended. WDYT?

@shairez shairez added STATUS-3: works as expected This issue is closed because the behavior is correct and expected and removed STATUS-1: needs triage New issue which needs to be triaged labels May 25, 2024
@shairez
Copy link
Contributor

shairez commented May 25, 2024

The workaround for this problem is to use "inline components" that allow you to track the right order

This is what we did in Qwik UI
https://github.com/qwikifiers/qwik-ui/blob/main/packages/kit-headless/src/components/tabs/tabs.tsx#L76

Closing as working as intended for now

@PatrickJS
Copy link
Member

we need docs on this

@shairez
Copy link
Contributor

shairez commented May 26, 2024

Thanks @PatrickJS ! good suggestion!

Let's open a new issue about it and reference this issue so we won't forget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
STATUS-3: works as expected This issue is closed because the behavior is correct and expected TYPE: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants