Skip to content

Do not inject portal if portal.url is set to 'false' in config file.#21936

Merged
9larsons merged 9 commits into
TryGhost:mainfrom
ltoinel:fix-member-js-injection-when-portal-off
Jun 9, 2026
Merged

Do not inject portal if portal.url is set to 'false' in config file.#21936
9larsons merged 9 commits into
TryGhost:mainfrom
ltoinel:fix-member-js-injection-when-portal-off

Conversation

@ltoinel

@ltoinel ltoinel commented Dec 19, 2024

Copy link
Copy Markdown
Contributor

Original PR comment:
If portal URL is set to false in the config as described in the Ghost documentation, we have to return nothing.
https://ghost.org/docs/config/

"The script can be relocated by changing the URL, or disabled entirely by setting "url": false."

Cathy's addition, upon 'adopting' this PR:
Tests added, confirming the behavior is as expected, including if the url is set to string false, boolean false, null, etc.

While I'd generally encourage self hosters who don't want the portal code to load to just turn off memberships, this leaves a route for a site to use the api functionality behind members, donations, etc, without including the portal loading code.

Likely to be a common want? No. Minimal impact on code maintainability? I think so.

@ltoinel ltoinel marked this pull request as ready for review December 20, 2024 22:21
@coderabbitai

coderabbitai Bot commented Jun 11, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

A guard clause was introduced in the getMembersHelper function within ghost/core/core/frontend/helpers/ghost_head.js. This clause checks if the scriptUrl value, retrieved from the portal configuration, is falsy. If it is, the function returns an empty string immediately, thereby skipping any further processing or script injection. No other parts of the function or related exports were modified.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ed612a1 and df8f853.

📒 Files selected for processing (1)
  • ghost/core/core/frontend/helpers/ghost_head.js (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Ghost-CLI tests
  • GitHub Check: Legacy tests (Node 20.11.1, mysql8)
  • GitHub Check: Legacy tests (Node 20.11.1, sqlite3)
  • GitHub Check: Unit tests (Node 22.13.1)
  • GitHub Check: Unit tests (Node 20.11.1)
  • GitHub Check: Acceptance tests (Node 22.13.1, mysql8)
  • GitHub Check: Acceptance tests (Node 20.11.1, mysql8)
  • GitHub Check: Acceptance tests (Node 20.11.1, sqlite3)
  • GitHub Check: Lint
🔇 Additional comments (1)
ghost/core/core/frontend/helpers/ghost_head.js (1)

61-63: Guard clause correctly prevents any portal assets from being injected when scriptUrl is falsy

The early-return handles both undefined and an explicit false value, matching the documented behaviour (“no portal member injected”). The rest of the function is skipped intentionally, so CTA styles and Stripe assets won’t be loaded either—consistent with disabling Portal altogether. Looks good.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@cathysarisky cathysarisky left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change makes a lot of sense to me. If the scriptUrl isn't set or is set to false, there's no reason to continue with the function.

It also brings the behavior in line with what the docs have said for a long time. :)

@cathysarisky

Copy link
Copy Markdown
Member

Hey @ltoinel , I'm not sure if you're still interested in pursuing this change or not, but I was able to snag a moment of dev attention for it. To be mergeable, it's going to need one or more tests added, showing that it results in the desired behavior. You might take a look at the tests for the ghost_head excludes behavior here as a starting point:

describe('respects values from excludes: ', function () {

@cathysarisky

Copy link
Copy Markdown
Member

Hey @ltoinel ! Since you didn't reply, I've pushed some tests that would cover the change in your PR, in hopes of getting this functionality ready to merge!

@cathysarisky cathysarisky changed the title If portal URL is set to false - No portal member injected Do not inject portal if portal.url is set to 'false' in config file. Jul 3, 2025
@ErisDS ErisDS self-assigned this Aug 4, 2025
@ErisDS ErisDS self-requested a review August 4, 2025 11:57
@ErisDS ErisDS added the community [triage] Community features and bugs label Sep 17, 2025
@9larsons 9larsons force-pushed the fix-member-js-injection-when-portal-off branch 5 times, most recently from a2bae04 to 324ebf4 Compare June 9, 2026 21:13
Ludovic Toinel and others added 9 commits June 9, 2026 16:19
If portal URL is false, we return no value.
The original approach used an early `return ''` that suppressed the
portal script, member styles (cta_styles) AND the Stripe script when
`portal.url` was falsy. Per maintainer guidance, only the portal script
should be skipped; member styles and Stripe must still be emitted.

Wrapped just the portal-script construction in `if (scriptUrl)`,
mirroring the falsy check used by the sibling getSearchHelper. This
removes the spurious `<script src="false">` (a 404 on every page) when
`portal.url: false` is configured, while leaving styles and Stripe
untouched. Dropped the special-case for the literal string 'false' in
favour of a plain falsy check, matching the documented boolean contract.

Tests assert the portal script is absent while cta_styles and Stripe
remain present; obsolete snapshots regenerated.
@9larsons 9larsons force-pushed the fix-member-js-injection-when-portal-off branch from 324ebf4 to f6d1e5f Compare June 9, 2026 21:19
@9larsons 9larsons merged commit ce37f00 into TryGhost:main Jun 9, 2026
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community [triage] Community features and bugs needs:review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants