-
Notifications
You must be signed in to change notification settings - Fork 69
fix: decode Object/Array attributes at SSR; comments first paint; kit idiom #221
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8171d63
fix: seed comments-thread from initial in willUpdate so SSR shows them
da6dbff
fix: decode HTML entities before JSON.parse for Object/Array attrs at…
ba43825
test: cover comments-thread SSR via the attribute form the page uses
9ab08a1
refactor: read tooltip/hover-card delay config via reactive props
0dd7127
refactor: read chat/comments form input via FormData, not querySelector
ec6e864
feat: document + enforce lit-style components over vanilla DOM
14117c1
feat: add prefer-signal-over-state-prop check rule
85a2b43
feat: per-file webjs-check-ignore escape hatch for check rules
cdf6500
refactor: keep lit-style as AGENTS guidance, not webjs check rules
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /** | ||
| * SSR regression for the comments thread first paint. | ||
| * | ||
| * The server-fetched `initial` comments are passed to <comments-thread> as a | ||
| * prop. They must appear in the SSR'd HTML (the first paint), not pop in after | ||
| * hydration. The component seeds its live `comments` signal from `initial` in | ||
| * willUpdate (which runs at SSR as of the framework's pre-render lifecycle), so | ||
| * renderToString shows the real list. The counterfactual: with no initial | ||
| * comments, the empty-state placeholder is what renders. | ||
| * | ||
| * Run: node --test test/comments/comments-ssr.test.ts | ||
| */ | ||
| import { test } from 'node:test'; | ||
| import assert from 'node:assert/strict'; | ||
|
|
||
| import { html } from '@webjsdev/core'; | ||
| import { renderToString } from '@webjsdev/core/server'; | ||
| import '../../modules/comments/components/comments-thread.ts'; | ||
|
|
||
| const SAMPLE = [ | ||
| { id: 'c1', authorName: 'Ada', createdAt: new Date('2020-01-01').toISOString(), body: 'first-ssr-comment' }, | ||
| { id: 'c2', authorName: 'Linus', createdAt: new Date('2020-01-02').toISOString(), body: 'second-ssr-comment' }, | ||
| ]; | ||
|
|
||
| // Assert on rendered CARD markup, not a body substring: the body text also | ||
| // appears inside the `initial="..."` attribute on the tag, so a bare substring | ||
| // match would false-pass even if the empty state rendered. The author name in | ||
| // a <strong> inside the card list is only present when a comment card rendered. | ||
| function rendersCards(out: string): boolean { | ||
| return /<ul[^>]*>[\s\S]*<strong[^>]*>Ada<\/strong>[\s\S]*<strong[^>]*>Linus<\/strong>/.test(out) | ||
| && !/No comments yet/.test(out); | ||
| } | ||
|
|
||
| test('SSR renders the initial comments via the property form (not the empty state)', async () => { | ||
| const out = await renderToString(html`<comments-thread postId="p1" .initial=${SAMPLE} ?signedIn=${false}></comments-thread>`); | ||
| assert.ok(rendersCards(out), `property form must render comment cards, got:\n${out}`); | ||
| }); | ||
|
|
||
| test('SSR renders the initial comments via the attribute form the post page uses', async () => { | ||
| // The post page renders `initial=${JSON.stringify(comments)}` (a string | ||
| // attribute), so this is the path that actually ships. It exercises both the | ||
| // willUpdate seed AND the Object-attribute entity decoding in the SSR walker. | ||
| const out = await renderToString(html`<comments-thread postId="p1" initial=${JSON.stringify(SAMPLE)} ?signedIn=${false}></comments-thread>`); | ||
| assert.ok(rendersCards(out), `attribute form must render comment cards, got:\n${out}`); | ||
| }); | ||
|
|
||
| test('COUNTERFACTUAL: with no initial comments, the empty-state placeholder renders', async () => { | ||
| const out = await renderToString(html`<comments-thread postId="p1" .initial=${[]} ?signedIn=${false}></comments-thread>`); | ||
| assert.match(out, /No comments yet/, 'empty-state shown when there are no comments'); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.