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

[✨] useRenderIndex #4757

Closed
shairez opened this issue Jul 8, 2023 · 1 comment
Closed

[✨] useRenderIndex #4757

shairez opened this issue Jul 8, 2023 · 1 comment
Labels
STATUS-3: won't be worked on We're not planning to work on this TYPE: enhancement New feature or request

Comments

@shairez
Copy link
Contributor

shairez commented Jul 8, 2023

Is your feature request related to a problem?

When rendering projected children during CSR, there's often times a need to know the current render index of the component, to prevent flickers.

For example, an accordion component with a selectedIndex set to 1.

Because Qwik is rendering child components during CSR in parallel, there's no guarantee that the components will run in the same order as they are defined in the JSX

So we can't rely on a counter that assigns the next index for each new child component.

Describe the solution you'd like

I would like to have a hook that will return a signal with the index of the current component in the context of either its parent Slot or element.

something like:

const thisCompIndexSig = useRenderIndex();

(for slots for example, because we are looping over the projected children inside of the visitor, we can maybe assign their index to the slot context and read it in the hook)

Describe alternatives you've considered

What we're doing now is to loop over child elements using querySelector during "visible task" to get the rendered index of each child component -

https://github.com/qwikifiers/qwik-ui/blob/main/packages/kit-headless/src/components/tabs/tabs.tsx#L214

Additional context

This solution is critical for Qwik UI and I'm sure other composable & reusable components that want to prevent a flicker on client side rendering (for example - when navigating using a Link component to a page with that reusable component).

@shairez shairez added TYPE: enhancement New feature or request STATUS-1: needs triage New issue which needs to be triaged labels Jul 8, 2023
@shairez shairez added STATUS-3: won't be worked on We're not planning to work on this and removed STATUS-1: needs triage New issue which needs to be triaged labels May 25, 2024
@shairez
Copy link
Contributor Author

shairez commented May 25, 2024

closing
context:
#3966 (comment)

@shairez shairez closed this as completed May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
STATUS-3: won't be worked on We're not planning to work on this TYPE: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant