Skip to content

Conversation

rschristian
Copy link
Member

@rschristian rschristian commented Aug 13, 2025

The 'GitHub Stars' example we have on the bottom of the home page is not great, IMO, as it's calling an external & hidden function in componentDidMount. Doesn't show much beyond that you can update state after mount to display some data, and even if we moved in the fetch call, it's a bit plain.

This PR swaps that out with a slightly altered version of our 'GitHub Repos' example from the REPL which showcases a similar situation (fetching external data & consuming it) but does so transparently and slightly more interestingly.

@rschristian rschristian changed the title refactor: Update handling of code blocks in HTML in markdown docs: Swap out "GitHub Stars" homepage demo for "GitHub Repos" Aug 13, 2025
@rschristian rschristian force-pushed the refactor/homepage-fetch-example branch from e8bf48c to 8546f8c Compare August 13, 2025 21:15
@rschristian rschristian force-pushed the refactor/homepage-fetch-example branch from 4801ebe to a527be6 Compare August 13, 2025 23:39
Comment on lines 10 to 11
fetch(`${SEARCH}?q=preact`)
.then(res => res.json())
.then(data => setItems((data && data.items) || []));
fetch(`https://api.github.com/orgs/${org}/repos?per_page=50`)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example has been altered to only return repositories from our organization rather than any repo with "preact" in the name or description; whilst there's nothing problematic in the data at this time, that could potentially change and as such it's a bit safer to only include a known data set.

Comment on lines 101 to +102
code({ text, lang }) {
const rawCodeBlockText = text.trim().replace('<br>', '\n');
const [code, source, runInRepl] = processRepl(rawCodeBlockText);
const [code, source, runInRepl] = processRepl(text.trim());
Copy link
Member Author

@rschristian rschristian Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now only includes "true" code blocks in markdown, i.e., those fenced with backticks. In those blocks, we have no reason to use <br>, so this was redudant. A confusing sort of redundant though, as I was wondering why it wasn't working for the examples on the home page when I altered it.

Leftover & unused fragment from #1205.

Comment on lines 174 to 177
<pre repl="false"><code class="language-jsx">
import TodoList from './todo-list';<br>
render(&lt;TodoList /&gt;, document.body);
import TodoList from './todo-list';<br>
render(<TodoList />, document.body);
</code></pre>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another "should've probably addressed in #1205". As marked no longer handles these code blocks, we don't need the entity encoding & can use dedent to get less gross indentation.

Still need to sprinkle <br> everywhere but not a whole heck of a lot can be done there.

Comment on lines -1401 to -1411
"node_modules/@jridgewell/source-map": {
"version": "0.3.5",
"resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.5.tgz",
"integrity": "sha512-UTYAUj/wviwdsMfzoSJspJxbkH5o1snzwX0//0ENX1u/55kkZZkcTZP6u9bwKGkv+dkk9at4m1Cpt0uY80kcpQ==",
"optional": true,
"peer": true,
"dependencies": {
"@jridgewell/gen-mapping": "^0.3.0",
"@jridgewell/trace-mapping": "^0.3.9"
}
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think most of this comes from #1280? Not too sure, just wanted to mention it as I made sure this didn't come from any local changes I made.

@@ -187,36 +189,69 @@ render(&lt;ToDoList /&gt;, document.body);
<div>
<h3>Zeige GitHub-Stars</h3>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Translations mostly hold (we're still displaying stars for repos on GitHub) so I'm not too concerned with the existing labels

'Cache-Control': 'public, max-age=3600, stale-if-error=86400'
'Cache-Control': 'public, max-age=86400, stale-if-error=86400'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumped the cache age here as we're not releasing anywhere near often enough for an hour-long cache to really be justified.

@rschristian rschristian marked this pull request as ready for review August 13, 2025 23:51
@rschristian rschristian force-pushed the refactor/homepage-fetch-example branch from 43dbcea to 466d207 Compare August 14, 2025 19:40
@rschristian rschristian merged commit 2b96587 into master Aug 14, 2025
5 checks passed
@rschristian rschristian deleted the refactor/homepage-fetch-example branch August 14, 2025 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants