question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Root component: invocation context

See original GitHub issue

Is your feature request related to a problem?

At the moment, Root component in a Qwik City project looks like this:

export default () => {
  return (
    <Html lang="en">
      <Head />
      <Body />
    </Html>
  );
};

Since it’s a simple component, I can’t do this:

export default () => {
  /* Invoking 'use*()' method outside of invocation context */
  const state = useStore({
    foo: 0  
  });
  
  return (
    <Html lang="en">
      <Head />
      <Body />
    </Html>
  );
};

And since it is not possible to change the structure of an HTML document, Qwik City has rewritten the html tag so that it can build its own contexts, thus available in the whole HTML document.

This way, the developer is out of control of the entire HTML document and out of the ability to do the same.

Describe the solution you’d like

export default () => {
  useQwikCity();

  /* Other use* methods that will be available in the whole document */
  
  return (
    <html lang="en">
      <Head />
      <Body />
    </html>
  );
};

Describe alternatives you’ve considered

I tried to use a Qwik component$ with tagname html as Root, but without success. In any case, Qwik City would not be importable.

Additional context

It is important to be able to control the entire HTML document in many real contexts: for example often the contents of the page (including title, description and body) come from a single request to the server/db, or for localization of the page, where the locale must be set from the html tag and must be shared with the whole page.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

0reactions
robisim74commented, Aug 11, 2022

For me the second option is ok, but besides the specific case of lang, it would be advisable not to lose the attributes of the Html tag (it could be confusing in the future). Why not modify the return content of Qwik City html.tsx like this?

return(
    <html {...props}>
      <Slot />
    </html>
  );

It seem works well

Read more comments on GitHub >

github_iconTop Results From Across the Web

context([key]) · Enzyme - GitHub Pages
context ([key]) => Any. Returns the context hash for the root node of the wrapper. Optionally pass in a prop name and it...
Read more >
UIViewRoot (Java EE 6 ) - Oracle Help Center
UIViewRoot is the UIComponent that represents the root of the UIComponent tree. This component renders markup as the response to Ajax requests.
Read more >
What is React Context And How To Use It?
React components structure is like a tree. Each child has only one parent and everyone is connected to the main root component.
Read more >
Context API – Vercel Docs
Let's assume that we want one of the link components to display the value of pageTitle which is declared in the root component,...
Read more >
Access HttpContext in ASP.NET Core - Microsoft Learn
Define a parameter in the root component to hold the data being passed to the app. Use the user-specific data within the app;...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found