@teambit/ui 1.0.499 → 1.0.500
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/artifacts/__bit_junit.xml +1 -1
- package/artifacts/preview/teambit_ui_foundation_ui-preview.js +1 -1
- package/artifacts/schema.json +505 -133
- package/artifacts/ui-bundle/scope/public/bit/index.html +1 -1
- package/artifacts/ui-bundle/scope/public/bit/service-worker.js +1 -1
- package/artifacts/ui-bundle/scope/public/bit/ssr/service-worker.js.map +1 -1
- package/dist/{preview-1734664696801.js → preview-1734878977623.js} +2 -2
- package/package.json +17 -17
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
2
|
<testsuites tests="0" failures="0" errors="0" skipped="0">
|
|
3
|
-
<testsuite name="teambit.ui-foundation/ui@1.0.
|
|
3
|
+
<testsuite name="teambit.ui-foundation/ui@1.0.500" tests="0" failures="0" errors="0" skipped="0"/>
|
|
4
4
|
</testsuites>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["teambit.ui-foundation/ui-preview"]=t():e["teambit.ui-foundation/ui-preview"]=t()}(self,(()=>(()=>{"use strict";var e={
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["teambit.ui-foundation/ui-preview"]=t():e["teambit.ui-foundation/ui-preview"]=t()}(self,(()=>(()=>{"use strict";var e={5189:(e,t,n)=>{var r={id:"teambit.ui-foundation/ui@1.0.500",homepage:"https://bit.cloud/teambit/ui-foundation/ui",exported:!0};function o(){const e=a(n(1594));return o=function(){return e},e}function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.Logo=void 0,o.__bit_component=r,a.__bit_component=r;const i=()=>o().default.createElement("div",{style:{height:"100%",display:"flex",justifyContent:"center"}},o().default.createElement("img",{style:{width:70},src:"https://static.bit.dev/extensions-icons/ui.svg"}));i.__bit_component=r,t.Logo=i},1594:e=>{e.exports=React}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var a=t[r]={exports:{}};return e[r](a,a.exports,n),a.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};n.r(r),n.d(r,{compositions:()=>u,compositions_metadata:()=>x,overview:()=>h});var o={};n.r(o),n.d(o,{default:()=>m});var a=n(5189);n(1594);const i=MdxJsReact,s=TeambitMdxUiMdxScopeContext;var l=["components"];function d(){return d=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},d.apply(null,arguments)}var c={},p="wrapper";function m(e){var t=e.components,n=function(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.includes(r))continue;n[r]=e[r]}return n}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.includes(n)||{}.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}(e,l);return(0,i.mdx)(p,d({},c,n,{components:t,mdxType:"MDXLayout"}),(0,i.mdx)(s.MDXScopeProvider,{components:{},mdxType:"MDXScopeProvider"},(0,i.mdx)("h2",null,"Server-side rendering"),(0,i.mdx)("p",null,"Server side rendering (or SSR) is done in the following form:"),(0,i.mdx)("pre",null,(0,i.mdx)("code",{parentName:"pre",className:"language-tsx"},"/** at server: */\nconst dom = ReactDom.renderToString(<MountPoint>{app}</MountPoint>);\nconst assets = { headers, scripts, ... };\nconst html = ReactDom.renderStaticMarkup(<Html assets={assets}/>);\nHtml.fillContent(html, dom);\nsend(html);\n\n/** at client: */\nReactDom.render(app, mountPoint);\n // or .hydrate()\n")),(0,i.mdx)("p",null,"We can then enrich the page with hooks:"),(0,i.mdx)("pre",null,(0,i.mdx)("code",{parentName:"pre",className:"language-tsx"},"/** at server: */\nlet context = hooks.serverInit();\nconst app = (\n <hooks.reactContext value={context}>\n <App />\n </hooks.reactContext>\n);\n\ncontext = hooks.onBeforeRender(app, context);\nconst dom = ...\n\nconst assets = hooks.serialize(context);\nconst html = ...\nsend(html);\n\n/** at client: */\nconst parsed = hooks.deserialize();\nconst context = hooks.browserInit(parsed);\nconst app = (\n <hooks.reactContext value={context}>\n <App />\n </hooks.reactContext>\n)\n\nhooks.onBeforeHydrate(app, context);\n\nconst ref = ReactDom.render(app, mountPoint);\n\nhooks.onHydrate(ref, context);\n")),(0,i.mdx)("p",null,"The rendering flow will ensure that the rendering Context will be unique per request, and separate between aspects."),(0,i.mdx)("h3",null,"Hiding elements before JS execution"),(0,i.mdx)("p",null,"Certain items look bad in the static HTML, and only get decent after JS executes. Tooltips are a notable example. They take up space in the DOM and only hide once their react code runs.",(0,i.mdx)("br",{parentName:"p"}),"\n","For these cases, use the convenience class ",(0,i.mdx)("inlineCode",{parentName:"p"},"--ssr-hidden"),". Add this to any misbehaving elements, and it will hide them using ",(0,i.mdx)("inlineCode",{parentName:"p"},"display: none")," until reactDom.render() is complete."),(0,i.mdx)("h3",null,".rehydrate vs .render()"),(0,i.mdx)("p",null,".rehydrate() attach a React virtual dom to a mount point, without asserting the virtual-dom matches the actual dom.",(0,i.mdx)("br",{parentName:"p"}),"\n",".render() updates the mount point to match the react virtual dom."),(0,i.mdx)("p",null,"On paper, ",(0,i.mdx)("inlineCode",{parentName:"p"},".rehydrate()")," should be the preferred option, with better performance.",(0,i.mdx)("br",{parentName:"p"}),"\n","In practice, ",(0,i.mdx)("inlineCode",{parentName:"p"},".render()"),' is backward compatible to React 15, and will know to "hydrate" according to the ',(0,i.mdx)("inlineCode",{parentName:"p"},"data-reactroot")," attribute on the mount point, with similar performance, and without revalidating the DOM.",(0,i.mdx)("br",{parentName:"p"}),"\n","ReactDOM will also show warnings in dev mode about mismatch between ssr dom and the client side dom."),(0,i.mdx)("h3",null,"Best practices"),(0,i.mdx)("ul",null,(0,i.mdx)("li",{parentName:"ul"},"Use ReactContext instead of trying to mutate ",(0,i.mdx)("inlineCode",{parentName:"li"},"App"),"."),(0,i.mdx)("li",{parentName:"ul"},"Use existing context object."),(0,i.mdx)("li",{parentName:"ul"},"Do not use other Aspects' context object."),(0,i.mdx)("li",{parentName:"ul"},"Try to keep process symmetrical between server and client;")),(0,i.mdx)("h4",null,"Example: Server side GraphQL"),(0,i.mdx)("p",null,"Graphql adds extra instructions to pre-fetch queries on the server:"),(0,i.mdx)("pre",null,(0,i.mdx)("code",{parentName:"pre",className:"language-tsx"}," // .registerRenderHooks() ?\n.registerRenderLifecycle({\n serverInit: ({ browser }) => {\n const { cookie } = browser;\n return { client: new Client(GQL_INTERNAL, { cookie }) };\n },\n beforeRender: ({ client }, app) => {\n await getDataFromTree(app);\n },\n serialize: ({ client }, app) => {\n return { json: JSON.stringify(client.extract()) };\n },\n deserialize: (raw) => {\n return { state: JSON.parse(raw) };\n },\n browserInit: ({ state }) => {\n return { client: new GraphqlClient(GQL_EXTERNAL, { cache: state })}\n },\n ReactContext: ({state, children}) =>\n <GqlContext client={state.client}>{children}</GqlContext>\n});\n")),(0,i.mdx)("h4",null,"Example: Server side Styled-components"),(0,i.mdx)("p",null,"StyledComponents extracts css from page, and adds it to the ",(0,i.mdx)("inlineCode",{parentName:"p"},"<head/>"),":"),(0,i.mdx)("pre",null,(0,i.mdx)("code",{parentName:"pre",className:"language-tsx"},".registerRenderLifecycle({\n init: () => {\n return { sheet: new ServerStyleSheet() };\n },\n serialize: (app, { sheet }) => {\n return { styles: sheet.getStyleTags() };\n };\n ReactContext: ({state, children}) =>\n <StyleSheetManager sheet={state.sheet}>{children}</StyleSheetManager>\n});\n"))))}m.isMDXComponent=!0;const u=[a],h=[o],x={compositions:[{displayName:"Logo",identifier:"Logo"}]};return r})()));
|