feat: create announcements banner - #617
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #617 +/- ##
==========================================
- Coverage 78.44% 77.95% -0.49%
==========================================
Files 157 159 +2
Lines 13967 14055 +88
Branches 1152 1152
==========================================
+ Hits 10956 10957 +1
- Misses 3006 3093 +87
Partials 5 5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
| File | Base | Head | Diff |
|---|---|---|---|
styles.css |
137.49 KB | 139.42 KB | +1.93 KB (+1.40%) |
addons.html |
262.76 KB | 262.77 KB | +11.00 B (+0.00%) |
assert.html |
330.20 KB | 330.21 KB | +11.00 B (+0.00%) |
async_context.html |
187.77 KB | 187.78 KB | +11.00 B (+0.01%) |
async_hooks.html |
159.91 KB | 159.92 KB | +11.00 B (+0.01%) |
buffer.html |
908.43 KB | 908.44 KB | +11.00 B (+0.00%) |
child_process.html |
381.89 KB | 381.91 KB | +11.00 B (+0.00%) |
cli.html |
501.86 KB | 501.87 KB | +11.00 B (+0.00%) |
cluster.html |
196.50 KB | 196.51 KB | +11.00 B (+0.01%) |
console.html |
146.97 KB | 146.98 KB | +11.00 B (+0.01%) |
crypto.html |
1.09 MB | 1.09 MB | +11.00 B (+0.00%) |
debugger.html |
54.42 KB | 54.43 KB | +11.00 B (+0.02%) |
deprecations.html |
505.55 KB | 505.56 KB | +11.00 B (+0.00%) |
dgram.html |
194.56 KB | 194.58 KB | +11.00 B (+0.01%) |
diagnostics_channel.html |
303.62 KB | 303.63 KB | +11.00 B (+0.00%) |
dns.html |
296.01 KB | 296.02 KB | +11.00 B (+0.00%) |
documentation.html |
38.24 KB | 38.25 KB | +11.00 B (+0.03%) |
domain.html |
105.30 KB | 105.31 KB | +11.00 B (+0.01%) |
embedding.html |
59.62 KB | 59.63 KB | +11.00 B (+0.02%) |
environment_variables.html |
44.24 KB | 44.25 KB | +11.00 B (+0.02%) |
errors.html |
461.85 KB | 461.87 KB | +11.00 B (+0.00%) |
esm.html |
155.54 KB | 155.55 KB | +11.00 B (+0.01%) |
events.html |
455.47 KB | 455.48 KB | +11.00 B (+0.00%) |
ffi.html |
116.78 KB | 116.79 KB | +11.00 B (+0.01%) |
fs.html |
1.43 MB | 1.43 MB | +11.00 B (+0.00%) |
globals.html |
230.58 KB | 230.59 KB | +11.00 B (+0.00%) |
http.html |
746.36 KB | 746.37 KB | +11.00 B (+0.00%) |
http2.html |
768.79 KB | 768.80 KB | +11.00 B (+0.00%) |
https.html |
150.55 KB | 150.56 KB | +11.00 B (+0.01%) |
index.html |
36.48 KB | 36.49 KB | +11.00 B (+0.03%) |
inspector.html |
171.58 KB | 171.59 KB | +11.00 B (+0.01%) |
intl.html |
58.34 KB | 58.35 KB | +11.00 B (+0.02%) |
module.html |
326.86 KB | 326.87 KB | +11.00 B (+0.00%) |
modules.html |
178.85 KB | 178.86 KB | +11.00 B (+0.01%) |
n-api.html |
807.45 KB | 807.46 KB | +11.00 B (+0.00%) |
net.html |
382.49 KB | 382.50 KB | +11.00 B (+0.00%) |
os.html |
142.93 KB | 142.94 KB | +11.00 B (+0.01%) |
packages.html |
154.85 KB | 154.86 KB | +11.00 B (+0.01%) |
path.html |
139.46 KB | 139.47 KB | +11.00 B (+0.01%) |
perf_hooks.html |
381.69 KB | 381.70 KB | +11.00 B (+0.00%) |
permissions.html |
55.84 KB | 55.85 KB | +11.00 B (+0.02%) |
process.html |
676.41 KB | 676.42 KB | +11.00 B (+0.00%) |
punycode.html |
63.39 KB | 63.40 KB | +11.00 B (+0.02%) |
querystring.html |
64.05 KB | 64.06 KB | +11.00 B (+0.02%) |
quic.html |
375.40 KB | 375.41 KB | +11.00 B (+0.00%) |
readline.html |
252.37 KB | 252.38 KB | +11.00 B (+0.00%) |
repl.html |
183.54 KB | 183.55 KB | +11.00 B (+0.01%) |
report.html |
176.11 KB | 176.13 KB | +11.00 B (+0.01%) |
single-executable-applications.html |
107.16 KB | 107.17 KB | +11.00 B (+0.01%) |
sqlite.html |
284.68 KB | 284.69 KB | +11.00 B (+0.00%) |
stream.html |
863.42 KB | 863.43 KB | +11.00 B (+0.00%) |
stream_iter.html |
352.58 KB | 352.59 KB | +11.00 B (+0.00%) |
string_decoder.html |
55.59 KB | 55.60 KB | +11.00 B (+0.02%) |
synopsis.html |
42.87 KB | 42.88 KB | +11.00 B (+0.03%) |
test.html |
783.85 KB | 783.86 KB | +11.00 B (+0.00%) |
timers.html |
133.70 KB | 133.71 KB | +11.00 B (+0.01%) |
tls.html |
373.99 KB | 374.00 KB | +11.00 B (+0.00%) |
tracing.html |
84.36 KB | 84.37 KB | +11.00 B (+0.01%) |
tty.html |
95.49 KB | 95.50 KB | +11.00 B (+0.01%) |
typescript.html |
53.67 KB | 53.68 KB | +11.00 B (+0.02%) |
url.html |
347.87 KB | 347.88 KB | +11.00 B (+0.00%) |
util.html |
695.97 KB | 695.98 KB | +11.00 B (+0.00%) |
v8.html |
339.30 KB | 339.31 KB | +11.00 B (+0.00%) |
vm.html |
371.00 KB | 371.01 KB | +11.00 B (+0.00%) |
wasi.html |
69.57 KB | 69.58 KB | +11.00 B (+0.02%) |
webcrypto.html |
522.20 KB | 522.21 KB | +11.00 B (+0.00%) |
webstreams.html |
357.40 KB | 357.42 KB | +11.00 B (+0.00%) |
worker_threads.html |
370.80 KB | 370.81 KB | +11.00 B (+0.00%) |
zlib.html |
290.44 KB | 290.45 KB | +11.00 B (+0.00%) |
zlib_iter.html |
88.26 KB | 88.27 KB | +11.00 B (+0.01%) |
There was a problem hiding this comment.
Pull request overview
This PR implements an announcement banner component that fetches configuration from a remote JSON endpoint to display global and version-specific banners on the API documentation pages. The banners support date-based activation/deactivation and can include links to relevant resources.
Changes:
- Added
AnnouncementBannercomponent that asynchronously fetches and displays banners from a remote config - Implemented
isBannerActiveutility function to filter banners based on date ranges - Added
versionMajorandremoteConfigfields to static data passed from server to client
Reviewed changes
Copilot reviewed 7 out of 9 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
src/generators/web/index.mjs |
Adds remote config URL to web generator default configuration |
src/generators/web/types.d.ts |
Adds remoteConfig type definition for the web generator |
src/generators/web/utils/data.mjs |
Extracts version major and remote config URL from server config to client static data |
src/generators/web/constants.mjs |
Registers AnnouncementBanner component in JSX imports map |
src/generators/jsx-ast/utils/buildContent.mjs |
Adds AnnouncementBanner to document layout above navigation bar |
src/generators/web/ui/utils/banner.mjs |
Implements date range checking logic for banner activation |
src/generators/web/ui/utils/__tests__/banner.test.mjs |
Comprehensive tests for banner date range logic |
src/generators/web/ui/components/AnnouncementBanner/types.d.ts |
Type definitions for banner entries and remote config structure |
src/generators/web/ui/components/AnnouncementBanner/index.jsx |
Main component that fetches config and renders active banners |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| <div> | ||
| {banners.map(banner => ( | ||
| <Banner key={banner.link} type={banner.type}> | ||
| {banner.link ? <a href={banner.link}>{banner.text}</a> : banner.text} |
There was a problem hiding this comment.
External URLs from the remote config are used directly in href attributes without validation. While React/Preact provides some protection against javascript: protocol URLs, there's still a potential security risk if the remote config source is compromised. Consider validating that banner.link uses an approved protocol (https://) or implementing an allowlist of acceptable domains to ensure only trusted URLs are rendered. This is especially important since the config is fetched from an external source.
There was a problem hiding this comment.
@avivkeller @ovflowd what do you think? is this necessary? We don't do this on nodejs website
|
@araujogui please be aware this must 100% be a client-side only component. Since the value of this comes from being able to fetch this at page load, as docs are built only once for each version. |
|
(this also means that this spec cannot ever change or needs to be forever retroactively compatible) |
It is |
uh, that also means we can't change the config url, so we should already create the config file on nodejs/node? |
Yeah... So we need to be very careful here 😓 |
We already have a |
We can use site.json, but note that it is not publicly available, the link would either need to be through github.com/ghraw or we'd need to move the file to be publicly available. |
I think github.com/ghraw is good enough |
IDK about that... |
|
I'd be fine with using github.com/ghraw at build time (like we do via nodevu on the site), but I don't think we should be reliant on hitting it client-side every time someone loads a page on the site, that feels like abuse of GitHub's service. Can we have a JSON file accessible via the site, or an API endpiont? |
We won't be loading this at build-time, cause it is supposed to be a client-side only, so it would hit indeed on every page load. I don't think github.com/ghraw has cache headers so it would not be good. |
Okay, maybe we could expose |
ovflowd
left a comment
There was a problem hiding this comment.
Let's put a block on this for now as this needs to be done thoughtfully
Description
Create announcements banner component
Validation
Related Issues
Fixes #327
Check List
node --run testand all tests passed.node --run format&node --run lint.