-
Notifications
You must be signed in to change notification settings - Fork 3
Amp ad free #468
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
base: master
Are you sure you want to change the base?
Amp ad free #468
Conversation
WalkthroughThe changes update the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Server (story-page.js)
participant Config
Client->>Server (story-page.js): GET /amp/story?subscriber=true
Server (story-page.js)->>Config: Fetch and merge additionalConfig
alt If query has subscriber=true
Server (story-page.js)->>Config: Merge { subscriber: true } into additionalConfig
end
Server (story-page.js)->>Client: Return AMP story HTML (with updated config)
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Possibly related PRs
Suggested reviewers
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
package.json (1)
36-36: Consider the implications of pinning dependency to exact pre-release version.The
@quintype/ampdependency has been changed from a flexible semver range (^2.22.0) to an exact pre-release version (2.22.1-amp-feat-fortune.0). This removes automatic patch updates and locks to a specific pre-release build.Consider whether this exact version pinning is intentional for the amp ad-free feature, or if a more flexible semver range would be appropriate once stable versions are available.
server/amp/handlers/story-page.js (1)
147-150: Consider input validation for the subscriber parameter.The current implementation trusts the query parameter value without validation. While checking for the exact string "true" provides some protection, consider additional validation for robustness.
Consider adding more explicit validation:
- if(req?.query?.subscriber === "true") { + if(req?.query?.subscriber === "true" && typeof req.query.subscriber === "string") { merge(additionalConfig, { subscriber: true }) }Or use a more defensive approach with a helper function for parameter validation.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (2)
package.json(2 hunks)server/amp/handlers/story-page.js(1 hunks)
🪛 Biome (1.9.4)
server/amp/handlers/story-page.js
[error] 148-148: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
🧰 Additional context used
🪛 Biome (1.9.4)
server/amp/handlers/story-page.js
[error] 148-148: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
🔇 Additional comments (2)
package.json (1)
3-3: Verify pre-release version stability before production deployment.The framework version has been updated to a pre-release version
7.34.5-amp-ad-free.2. Pre-release versions may contain unstable features or bugs that could impact production stability.Please verify that this pre-release version has been thoroughly tested and is ready for production use, or consider using a stable release version.
server/amp/handlers/story-page.js (1)
147-150: Logic placement and implementation approach approved.The subscriber flag logic is well-positioned in the function flow - after async configuration fetching but before AMP HTML generation. The comment clearly explains the purpose for ad-free AMP stories, and the merge approach maintains the existing configuration structure.
| if(req && req.query && req.query.subscriber === "true") { | ||
| merge(additionalConfig, { subscriber: true }) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve condition safety and consider merge target consistency.
The current condition checking and merge operation have a few areas for improvement:
- As suggested by static analysis, use optional chaining for safer property access
- Consider whether
additionalConfigis the correct merge target, given thatmergedAdditionalConfigis used later in the function
Apply this diff to address the optional chaining and ensure consistent merge target:
- if(req && req.query && req.query.subscriber === "true") {
- merge(additionalConfig, { subscriber: true })
- }
+ if(req?.query?.subscriber === "true") {
+ merge(mergedAdditionalConfig.length ? mergedAdditionalConfig : additionalConfig, { subscriber: true })
+ }Alternatively, if additionalConfig is intentionally the target regardless of mergedAdditionalConfig:
- if(req && req.query && req.query.subscriber === "true") {
+ if(req?.query?.subscriber === "true") {
merge(additionalConfig, { subscriber: true })
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if(req && req.query && req.query.subscriber === "true") { | |
| merge(additionalConfig, { subscriber: true }) | |
| } | |
| if (req?.query?.subscriber === "true") { | |
| merge( | |
| mergedAdditionalConfig.length ? mergedAdditionalConfig : additionalConfig, | |
| { subscriber: true } | |
| ) | |
| } |
🧰 Tools
🪛 Biome (1.9.4)
[error] 148-148: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
🤖 Prompt for AI Agents
In server/amp/handlers/story-page.js around lines 148 to 150, update the
condition to use optional chaining (e.g., req?.query?.subscriber) for safer
property access to avoid runtime errors if any part is undefined. Also, verify
if the merge target should be mergedAdditionalConfig instead of additionalConfig
to maintain consistency with later usage; if so, change the merge call to target
mergedAdditionalConfig. Adjust the code accordingly to ensure both safer checks
and consistent merge target.
Description
Please include the summary of the change made. Please include the required context here. Please include the issue reference for the fix and the dependencies reference for the change.
Fixes # (issue-reference)
Dependencies # (dependency-issue-reference)
Documentation # (link to the corresponding documentation changes)
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Checklist:
Summary by CodeRabbit
New Features
Chores