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

feat!: ssr #2762

Merged
merged 84 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 83 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
8e9564a
fix(core)!: remove side effects from core import
bennypowers May 19, 2024
79fa987
feat(tools): ssr test page
bennypowers May 19, 2024
3850511
test(accordion): ssr tests
bennypowers May 19, 2024
06d61d7
test(avatar): ssr tests
bennypowers May 19, 2024
9a001c6
test(back-to-top): ssr
bennypowers May 19, 2024
acf3b38
test(background-image): ssr
bennypowers May 19, 2024
c931c5a
test(badge): ssr
bennypowers May 19, 2024
fd37c48
test(banner): ssr
bennypowers May 20, 2024
3037687
test(button): ssr
bennypowers May 20, 2024
58389ff
test(card): ssr
bennypowers May 20, 2024
3f7eec1
test(chip): ssr
bennypowers May 20, 2024
d292433
test(clipboard-copy): ssr
bennypowers May 20, 2024
3359f45
test(code-block): ssr
bennypowers May 20, 2024
56b0858
test(dropdown): ssr
bennypowers May 20, 2024
a8efb05
test(icon): ssr
bennypowers May 20, 2024
696a865
test(jump-links): ssr
bennypowers May 20, 2024
240c7e7
test(label): ssr
bennypowers May 20, 2024
0ca0ea5
test(modal): ssr
bennypowers May 20, 2024
6b0f40a
test(panel): ssr
bennypowers May 20, 2024
b4d9c11
test(popover): ssr
bennypowers May 20, 2024
80e1227
test(progress): ssr
bennypowers May 20, 2024
70d464f
test(progress-stepper): ssr
bennypowers May 20, 2024
18f9f85
test(select): ssr
bennypowers May 20, 2024
5f9f527
test(spinner): ssr
bennypowers May 20, 2024
4b71fe5
test(switch): ssr
bennypowers May 20, 2024
11294cd
test(table): ssr
bennypowers May 20, 2024
eba47b9
test(tabs): ssr
bennypowers May 20, 2024
74eef92
test(text-area): ssr
bennypowers May 20, 2024
06ec5b9
test(text-area): ssr
bennypowers May 20, 2024
9ddecdd
test(tile): ssr
bennypowers May 20, 2024
725623d
test(timestamp): ssr
bennypowers May 20, 2024
57e381d
test(tooltip): ssr
bennypowers May 20, 2024
bac43ed
feat(create-element): ssr tests
bennypowers May 20, 2024
34d1c18
feat(tools): automatic ssr demos
bennypowers May 20, 2024
f774e40
fix(tools): shim module
bennypowers May 20, 2024
a9e84f7
docs: changesets
bennypowers May 20, 2024
39cfe7a
test: remove cruft
bennypowers May 20, 2024
0e21463
fix(tools): ssr error reports
bennypowers May 20, 2024
db7a593
test: playwright config for ssr
bennypowers May 20, 2024
600ae91
chore: ssr test workflow
bennypowers May 20, 2024
09dc368
fix(tools): ssr error status message
bennypowers May 20, 2024
663f414
chore: ssr test workflow
bennypowers May 20, 2024
9c92325
chore: ssr test workflow
bennypowers May 20, 2024
d6f9acf
chore: ignore reports
bennypowers May 20, 2024
a485351
fix(accordion): ssrability
bennypowers May 20, 2024
a7cad9d
fix(back-to-top): ssrability
bennypowers May 20, 2024
96c9a45
docs: jsdoc for ssr tests
bennypowers May 20, 2024
e5fcc99
chore: test workflow in ci
bennypowers May 20, 2024
f0c857c
fix(core): fix Logger for ssr
bennypowers May 20, 2024
5e5859d
style: whitespace
bennypowers May 21, 2024
6d40990
chore: better elements build
bennypowers May 21, 2024
45db099
fix(core): more ssr-able controllers
bennypowers May 21, 2024
17841e8
test(back-to-top): ssrable demos
bennypowers May 21, 2024
f9f8cd4
fix(tools): redirects for demos in dev server
bennypowers May 21, 2024
804842f
fix(tools): ssr files
bennypowers May 21, 2024
82b1e02
test(background-image): ssrable demos
bennypowers May 21, 2024
35ba371
fix(tools): 11ty demo images
bennypowers May 21, 2024
674de76
fix(core): floating dom controller more ssrable
bennypowers May 21, 2024
7ca39e5
feat(tools): export ssr helpers
bennypowers May 21, 2024
23340f2
fix(code-block): ssrable
bennypowers May 21, 2024
d9296ee
fix(jump-links): ssrable
bennypowers May 21, 2024
d2493d7
fix(core): ssrable ScrollSpyController
bennypowers May 21, 2024
9ab5a8b
fix(progress-stepper): ssrable
bennypowers May 21, 2024
d49b640
fix(popover): ssrable
bennypowers May 21, 2024
735b2f8
fix(core): ssrable lbc
bennypowers May 21, 2024
540b811
fix(icon): ssr
bennypowers May 21, 2024
926987a
fix(select): ssrable
bennypowers May 21, 2024
d18cd2f
fix(table): ssrable
bennypowers May 21, 2024
4a3d9fc
fix(text-area): ssrable
bennypowers May 21, 2024
836d10d
fix(text-input): ssrable
bennypowers May 21, 2024
8a4aad5
fix(tooltip): ssrable
bennypowers May 21, 2024
a4383fe
chore: pr reports
bennypowers May 21, 2024
4f920cc
fix(tools): update playwright
bennypowers May 21, 2024
1a3a5db
chore: ssr workflow
bennypowers May 21, 2024
5c2ac75
chore: ssr workflow
bennypowers May 21, 2024
59bbca7
chore: actions versions
bennypowers May 21, 2024
7d721d4
chore: ssr workflow
bennypowers May 21, 2024
3598138
chore: ssr workflow
bennypowers May 21, 2024
6a2e676
chore: ssr workflow
bennypowers May 21, 2024
54da015
chore: ssr workflow
bennypowers May 21, 2024
7ccfca1
chore: ssr workflow
bennypowers May 21, 2024
7360236
chore: ssr workflow
bennypowers May 21, 2024
311d03d
chore: ssr workflow
bennypowers May 21, 2024
5a0c5d6
Merge branch 'staging/4.0' into fix/ssr/core-initial
bennypowers Jun 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changeset/few-lands-feel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"@patternfly/pfe-core": major
---
Removed global `pfeLog` feature
4 changes: 4 additions & 0 deletions .changeset/mean-tires-ask.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"@patternfly/pfe-core": major
---
Removed `window.PfeConfig` global config object
4 changes: 4 additions & 0 deletions .changeset/polite-rules-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"@patternfly/pfe-core": major
---
Removed global `auto-reveal` feature
4 changes: 4 additions & 0 deletions .changeset/public-yaks-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"@patternfly/pfe-core": patch
---
Context: `makeContextRoot` no longer crashes SSR processes
4 changes: 4 additions & 0 deletions .changeset/thirty-hounds-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"@patternfly/pfe-core": major
---
Removed global `trackPerformance` feature
4 changes: 2 additions & 2 deletions .github/workflows/bundle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
if: github.repository == 'patternfly/patternfly-elements'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: npm
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- uses: actions/setup-node@v3
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: npm
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
if: github.repository == 'patternfly/patternfly-elements'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: npm
Expand Down
78 changes: 69 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ env:
# Bring color into the GitHub terminal
FORCE_COLOR: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PLAYWRIGHT_REPORT_DIR: test-report

# https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/
ACTIONS_ALLOW_UNSECURE_COMMANDS: "true"
Expand All @@ -45,11 +46,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Configures the node version used on GitHub-hosted runners
- name: Configure node version
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '20'
cache: npm
Expand All @@ -61,17 +62,16 @@ jobs:
id: lint
run: npm run lint


test:
name: Run test suite (Web Test Runner)
name: Unit Tests (Web Test Runner)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Configures the node version used on GitHub-hosted runners
- name: Configure node version
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '20'
cache: npm
Expand All @@ -91,6 +91,67 @@ jobs:
report_paths: test-results/test-results.xml
fail_on_failure: true # fail the actions run if the tests failed

ssr:
name: SSR Tests (Playwright)
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/playwright:v1.44.0-jammy
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: npm
- run: npm ci --prefer-offline
- run: npm run build

- name: Run tests
run: npx playwright test -g ssr --update-snapshots
env:
HOME: /root

- uses: actions/upload-artifact@v2
if: always()
with:
name: ${{ env.PLAYWRIGHT_REPORT_DIR }}
path: ${{ env.PLAYWRIGHT_REPORT_DIR }}/
retention-days: 30

publish_report:
name: Publish Playwright Report
# using always() is not ideal here, because it would also run if the workflow was cancelled
if: "success() || needs.ssr.result == 'failure'"
needs:
- ssr
runs-on: ubuntu-latest
continue-on-error: true
env:
HTML_REPORT_URL_PATH: reports/${{ github.ref_name }}/${{ github.run_id }}/${{ github.run_attempt }}
steps:
- uses: actions/checkout@v4
- name: Download zipped HTML report
uses: actions/download-artifact@v2
with:
name: ${{ env.PLAYWRIGHT_REPORT_DIR }}
path: ${{ env.PLAYWRIGHT_REPORT_DIR }}/
- name: Upload to Github Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: ${{ env.PLAYWRIGHT_REPORT_DIR }}
target-folder: ${{ env.HTML_REPORT_URL_PATH }}
- name: Add comment to PR
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
number: ${{ github.event.inputs.issueNumber }}
append: true
header: "${{ github.sha }}"
hide: true
hide_details: true
message: |
**SSR Test Run for ${{ github.sha }}**: [Report](https://patternfly.github.io/patternfly-elements/${{ env.HTML_REPORT_URL_PATH }})

# Validate the build to main was successful; open an issue if not
build:
name: Compile project
runs-on: ubuntu-latest
Expand All @@ -116,13 +177,13 @@ jobs:
)
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

# Configures the node version used on GitHub-hosted runners
- name: Configure node version
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: npm
Expand All @@ -138,7 +199,6 @@ jobs:
id: release-dry
run: npm run prepublishOnly -ws --if-present

# Validate the build to main was successful; open an issue if not
validate:
name: Validate successful build on main
needs:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/visual-regression.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ jobs:
e2e:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: npm
Expand All @@ -42,7 +42,7 @@ jobs:
lighthouse:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Generate URLs
id: urls
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pfe.min.js
**/*.LEGAL.txt
*.tsbuildinfo
test-results
test-report

/elements/react

Expand Down
4 changes: 2 additions & 2 deletions core/pfe-core/controllers/floating-dom-controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Placement } from '@floating-ui/dom';
import type { ReactiveController, ReactiveControllerHost } from 'lit';
import type { LitElement, ReactiveController, ReactiveControllerHost } from 'lit';
import type { StyleInfo } from 'lit/directives/style-map.js';
import type { OffsetOptions as Offset } from '@floating-ui/core';

Expand Down Expand Up @@ -100,7 +100,7 @@ export class FloatingDOMController implements ReactiveController {
) {
host.addController(this);
this.#options = {
invoker: (host instanceof HTMLElement ? () => host : () => undefined),
invoker: (() => host as LitElement),
shift: true,
...options,
};
Expand Down
21 changes: 18 additions & 3 deletions core/pfe-core/controllers/internals-controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { ReactiveController, ReactiveControllerHost } from 'lit';
import {
isServer,
type ReactiveController,
type ReactiveControllerHost,
type LitElement,
} from 'lit';

function isARIAMixinProp(key: string): key is keyof ARIAMixin {
return key === 'role' || key.startsWith('aria');
Expand Down Expand Up @@ -146,7 +151,11 @@ export class InternalsController implements ReactiveController, ARIAMixin {

/** True when the control is disabled via it's containing fieldset element */
get formDisabled() {
return this.element?.matches(':disabled') || this._formDisabled;
if (isServer) {
return this._formDisabled;
} else {
return this.element?.matches(':disabled') || this._formDisabled;
}
}

get labels() {
Expand All @@ -166,7 +175,13 @@ export class InternalsController implements ReactiveController, ARIAMixin {
}

private get element() {
return this.host instanceof HTMLElement ? this.host : this.options?.getHTMLElement?.();
if (isServer) {
// FIXME(bennyp): a little white lie, which may break
// when the controller is applied to non-lit frameworks.
return this.host as LitElement;
} else {
return this.host instanceof HTMLElement ? this.host : this.options?.getHTMLElement?.();
}
}

private internals!: ElementInternals;
Expand Down
6 changes: 4 additions & 2 deletions core/pfe-core/controllers/listbox-controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ReactiveController, ReactiveControllerHost } from 'lit';
import { isServer, type ReactiveController, type ReactiveControllerHost } from 'lit';

export interface ListboxAccessibilityController<
Item extends HTMLElement
Expand Down Expand Up @@ -56,7 +56,9 @@ export class ListboxController<Item extends HTMLElement> implements ReactiveCont
if (!constructingAllowed) {
throw new Error('ListboxController must be constructed with `ListboxController.of()`');
}
if (!(host instanceof HTMLElement) && typeof _options.getHTMLElement !== 'function') {
if (!isServer
&& !(host instanceof HTMLElement)
&& typeof _options.getHTMLElement !== 'function') {
throw new Error(
`ListboxController requires the host to be an HTMLElement, or for the initializer to include a \`getHTMLElement()\` function`,
);
Expand Down
4 changes: 2 additions & 2 deletions core/pfe-core/controllers/logger.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { ReactiveController, ReactiveControllerHost } from 'lit';
import { isServer, type ReactiveController, type ReactiveControllerHost } from 'lit';

export class Logger implements ReactiveController {
private static logDebug: boolean;

private static instances = new WeakMap<ReactiveControllerHost, Logger>();

private get prefix() {
if (this.host instanceof HTMLElement) {
if (!isServer && this.host instanceof HTMLElement) {
return `[${this.host.localName}${this.host.id ? `#${this.host.id}` : ''}]`;
} else {
return `[${this.host.constructor.name}]`;
Expand Down
2 changes: 1 addition & 1 deletion core/pfe-core/controllers/overflow-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class OverflowController implements ReactiveController {

static {
// on resize check for overflows to add or remove scroll buttons
window.addEventListener('resize', () => {
globalThis.addEventListener?.('resize', () => {
for (const instance of this.#instances) {
instance.onScroll();
}
Expand Down
6 changes: 3 additions & 3 deletions core/pfe-core/controllers/scroll-spy-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class ScrollSpyController implements ReactiveController {
#rootMargin?: string;
#threshold: number | number[];

#rootNode: Node;
#getRootNode: () => Node;
#getHash: (el: Element) => string | null;

get #linkChildren(): Element[] {
Expand Down Expand Up @@ -92,7 +92,7 @@ export class ScrollSpyController implements ReactiveController {
this.#rootMargin = options.rootMargin;
this.#activeAttribute = options.activeAttribute ?? 'active';
this.#threshold = options.threshold ?? 0.85;
this.#rootNode = options.rootNode ?? host.getRootNode();
this.#getRootNode = () => options.rootNode ?? host.getRootNode();
this.#getHash = options?.getHash ?? ((el: Element) => el.getAttribute('href'));
}

Expand All @@ -101,7 +101,7 @@ export class ScrollSpyController implements ReactiveController {
}

#initIo() {
const rootNode = this.#rootNode;
const rootNode = this.#getRootNode();
if (rootNode instanceof Document || rootNode instanceof ShadowRoot) {
const { rootMargin, threshold, root } = this;
this.#io = new IntersectionObserver(r => this.#onIo(r), { root, rootMargin, threshold });
Expand Down
Loading
Loading