Root component: invocation context
See original GitHub issueIs 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:
- Created a year ago
- Comments:10 (10 by maintainers)
Top GitHub Comments
Fixed! https://github.com/BuilderIO/qwik/commit/3e18804db2d7937db4576023bfba594e5d6e925d
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?It seem works well