Skip to content

Commit

Permalink
docs: load demo deps early on (#2119)
Browse files Browse the repository at this point in the history
* docs: load demo deps early on

Closes #2097

* docs: eagerly load tag definition

* docs: streamline module loading

try to load ssr support modules in one place only, see if that still
works with webkit

* docs: markdown tables ftw

this commit is especially for @zeroedin's benefit
  • Loading branch information
bennypowers authored Jan 14, 2025
1 parent 04fc9a5 commit f7666d7
Show file tree
Hide file tree
Showing 17 changed files with 185 additions and 374 deletions.
22 changes: 21 additions & 1 deletion docs/_includes/layouts/base.njk
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,27 @@
</style>
</noscript>

{% include "../partials/javascript/global.html" %}
<script type="importmap">{{ importMap | dump(2) | safe }}</script>

{# ensure SSR support modules are loaded first #}
{% include 'partials/javascript/dsd-init.html' %}

{# load all components #}
{% for tag in importElements %}
<script type="module">import '@rhds/elements/{{tag}}/{{tag}}.js';</script>
{% endfor %}

{# only load components that need hydrated (aka interactivity) #}
<script type="module">
import '@rhds/elements/rh-button/rh-button.js';
import '@uxdot/elements/uxdot-copy-permalink.js';
import '@uxdot/elements/uxdot-sidenav.js';
import '@uxdot/elements/uxdot-example.js';
</script>

<script async src="https://ga.jspm.io/npm:[email protected]/dist/es-module-shims.js"></script>


</head>

<body dsd-pending class="{{ extraPageClasses }}">
Expand Down
4 changes: 3 additions & 1 deletion docs/_includes/layouts/pages/element.11ty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ export default class ElementsPage extends Renderer<Context> {
</noscript>
<script type="module" data-helmet>
// although we load these ssr support modules elsewhere, we still
// need them here to ensure no double-rendering on webkit
import '/assets/javascript/ssr-support.js';
import '@uxdot/elements/uxdot-copy-button.js';
import '@uxdot/elements/uxdot-copy-permalink.js';
import '@uxdot/elements/uxdot-best-practice.js';
Expand Down Expand Up @@ -961,4 +964,3 @@ export default class ElementsPage extends Renderer<Context> {
}
}
};

3 changes: 3 additions & 0 deletions docs/_includes/layouts/pages/has-toc.njk
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ layout: layouts/base.njk
data-helmet>

<script type="module" data-helmet>
// although we load these ssr support modules elsewhere, we still
// need them here to ensure no double-rendering on webkit
import '/assets/javascript/ssr-support.js';
import '@uxdot/elements/uxdot-toc.js';
</script>

Expand Down
13 changes: 13 additions & 0 deletions docs/_includes/partials/javascript/dsd-init.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script type="module">
// although we load these ssr support modules elsewhere, we still
// need them here to ensure no double-rendering on webkit
import '/assets/javascript/ssr-support.js';
// include these, which are often internal to elements,
// and are definitely required by context-picker and context-demo
// to avoid SSR defer-hydration bugs and SSR double-rendering bugs
import '@rhds/elements/rh-icon/rh-icon.js';
import '@rhds/elements/rh-surface/rh-surface.js';
import '@rhds/elements/rh-button/rh-button.js';
import '@rhds/elements/rh-tooltip/rh-tooltip.js';
import '@rhds/elements/rh-tag/rh-tag.js';
</script>
27 changes: 0 additions & 27 deletions docs/_includes/partials/javascript/global.html

This file was deleted.

6 changes: 4 additions & 2 deletions docs/about/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ order: 20
bodyClasses: page-docs
tags:
- about
importElements:
- rh-tile
---

<script type="module" data-helmet>
import '@rhds/elements/rh-tile/rh-tile.js';
</script>

<link data-helmet rel="stylesheet" href="/assets/packages/@rhds/elements/elements/rh-tile/rh-tile-lightdom.css">

<style data-helmet>
Expand Down
6 changes: 4 additions & 2 deletions docs/accessibility/accessibility-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ permalink: /accessibility/accessibility-tools/index.html
tags:
- accessibility
order: 10
importElements:
- rh-blockquote
---

<script type="module" data-helmet>
import '@rhds/elements/rh-blockquote/rh-blockquote.js';
</script>

## Automated Accessibility Tools

Automated tools can help you quickly identify many potential high-impact accessibility issues. Among such tools are free browser extensions like:
Expand Down
10 changes: 6 additions & 4 deletions docs/accessibility/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ title: Content
tags:
- accessibility
order: 40
importElements:
- rh-code-block
- rh-blockquote
- rh-table
---

<link data-helmet
rel="stylesheet"
href="/assets/packages/@rhds/elements/elements/rh-table/rh-table-lightdom.css">

<script type="module" data-helmet>
import '@rhds/elements/rh-code-block/rh-code-block.js';
import '@rhds/elements/rh-blockquote/rh-blockquote.js';
import '@rhds/elements/rh-table/rh-table.js';
</script>

<style data-helmet>
rh-blockquote {
display: block;
Expand Down
6 changes: 4 additions & 2 deletions docs/accessibility/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ title: Fundamentals
tags:
- accessibility
order: 75
importElements:
- rh-blockquote
---

<script type="module" data-helmet>
import '@rhds/elements/rh-blockquote/rh-blockquote.js';
</script>

<style>
rh-blockquote {
display: block;
Expand Down
6 changes: 4 additions & 2 deletions docs/accessibility/screen-readers.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ permalink: /accessibility/screen-readers/index.html
tags:
- accessibility
order: 100
importElements:
- rh-tile
---

<script type="module" data-helmet>
import '@rhds/elements/rh-tile/rh-tile.js';
</script>

<link rel="stylesheet"
data-helmet
href="/assets/packages/@rhds/elements/elements/rh-tile/rh-tile-lightdom.css">
Expand Down
5 changes: 5 additions & 0 deletions docs/assets/javascript/ssr-support.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// dsd polyfill needs to happen before hydration attempts
// lit-element-hydrate-support needs to be included before lit is loaded
import '/assets/javascript/dsd-polyfill.js';
import '@lit-labs/ssr-client/lit-element-hydrate-support.js';
import 'element-internals-polyfill';
12 changes: 4 additions & 8 deletions docs/elements/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@
<link rel="stylesheet" href="/styles/demo/styles.css" media="all">

<script type="importmap">{{ importMap | dump(2) | safe }}</script>

{# ensure SSR support modules are loaded first #}
{% include 'partials/javascript/dsd-init.html' %}

<script type="module">
// dsd polyfill needs to happen before hydration attempts
// lit-element-hydrate-support needs to be included before lit is loaded
import '/assets/javascript/dsd-polyfill.js';
import '@lit-labs/ssr-client/lit-element-hydrate-support.js';
import 'element-internals-polyfill';
// include these, which are often internal to elements, to avoid SSR defer-hydration bugs
import '@rhds/elements/rh-icon/rh-icon.js';
import '@rhds/elements/rh-surface/rh-surface.js';
// load up the demo and picker
import '@rhds/elements/lib/elements/rh-context-picker/rh-context-picker.js';
import '@rhds/elements/lib/elements/rh-context-demo/rh-context-demo.js';
Expand Down
8 changes: 5 additions & 3 deletions docs/get-started/developers/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ subnav:
collection: sortedDevelopers
order: 00
order: 20
importElements:
- rh-card
- rh-cta
---

<script type="module" data-helmet>
import '@rhds/elements/rh-card/rh-card.js';
import '@rhds/elements/rh-cta/rh-cta.js';
</script>

<style data-helmet>
.grid > rh-card {
display: grid;
Expand Down
6 changes: 4 additions & 2 deletions docs/get-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ title: Overview
order: 00
tags:
- getstarted
importElements:
- rh-tile
---

<link data-helmet rel="stylesheet" href="/assets/packages/@rhds/elements/elements/rh-tile/rh-tile-lightdom.css">

<script type="module" data-helmet>
import '@rhds/elements/rh-tile/rh-tile.js';
</script>

<style data-helmet>
#get-started-nav {
margin-block-start: var(--rh-space-2xl, 32px);
Expand Down
5 changes: 2 additions & 3 deletions docs/patterns/logo-wall/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ tags:
subnav:
collection: logowallPatterns
order: 4
importElements:
- rh-cta
- rh-surface
---

<script type="module" data-helmet>
import '@rhds/elements/rh-surface/rh-surface.js';
import '@rhds/elements/rh-cta/rh-cta.js';
import '@rhds/elements/lib/elements/rh-context-picker/rh-context-picker.js';
</script>

Expand Down
Loading

0 comments on commit f7666d7

Please sign in to comment.