Skip to content

Fix: Prevent "Powered by Ghost" from opening two tabs#24623

Open
niranjan-uma-shankar wants to merge 3 commits intoTryGhost:mainfrom
niranjan-uma-shankar:fix-powered-by-click
Open

Fix: Prevent "Powered by Ghost" from opening two tabs#24623
niranjan-uma-shankar wants to merge 3 commits intoTryGhost:mainfrom
niranjan-uma-shankar:fix-powered-by-click

Conversation

@niranjan-uma-shankar
Copy link
Contributor

@niranjan-uma-shankar niranjan-uma-shankar commented Aug 7, 2025

Summary

In Portal, clicking on "Powered by Ghost", in the overlay that appears in the signup modal, opens ghost.org in two tabs. Example:

Screen.Recording.2025-08-07.at.7.40.18.PM.mov

Root cause:

  • The element contains both a href attribute and an onClick handler, leading to two tabs for a single click.

Fix

  • Remove the redundant onClick handler.

Testing Instructions

  • Visit http://localhost:2368/ and click on the "Subscribe" button in the header.
  • In the modal overlay, click on "Powered by Ghost" and verify that it opens ghost.org in a single new tab.
  • Run the test (verify that node version is >22):
cd apps/portal && yarn test portal-links.test.js 

This change ensures that clicking on the Powered By link does not open two tabs.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 7, 2025

Walkthrough

Removed the custom onClick handler from the anchor in apps/portal/src/components/common/PoweredBy.js that previously called window.open('https://ghost.org', '_blank'). The anchor now relies on href="https://ghost.org" with target="_blank" and rel="noopener noreferrer" and includes a data-test-powered-by attribute. Added a test in apps/portal/src/tests/portal-links.test.js that renders the portal signup, finds the "powered by ghost" link in the popup, and asserts href, target, rel, and absence of an onClick handler. No other component structure, content, or exports changed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes


📜 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 f0906e2 and 16dbde3.

📒 Files selected for processing (1)
  • apps/portal/src/components/common/PoweredBy.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/portal/src/components/common/PoweredBy.js
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
  • 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate unit tests to generate unit tests for 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.

@niranjan-uma-shankar niranjan-uma-shankar changed the title Removed redundant onClick handler from Powered By Portal component Fix: Prevent "Powered by Ghost" from opening two tabs Aug 7, 2025
@niranjan-uma-shankar niranjan-uma-shankar marked this pull request as ready for review August 11, 2025 13:27
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 (1)
apps/portal/src/components/common/PoweredBy.js (1)

14-14: Accessibility: hide decorative SVG from screen readers.

Mark the logo as decorative so the link’s accessible name is just “Powered by Ghost.”

-                <GhostLogo />
+                <GhostLogo aria-hidden="true" focusable="false" />
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 888ae06 and f2844e3.

📒 Files selected for processing (1)
  • apps/portal/src/components/common/PoweredBy.js (1 hunks)
🔇 Additional comments (1)
apps/portal/src/components/common/PoweredBy.js (1)

13-16: Fix looks good: removes double navigation and keeps tabnabbing protections.

Relying on the anchor’s default behavior with target="_blank" and rel="noopener noreferrer" resolves the two-tab issue and preserves security best practices.

Adds a data-test-powered-by attribute to the external link to simplify E2E targeting.
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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)
apps/portal/src/tests/portal-links.test.js (2)

362-362: Make the rel assertion order-insensitive.

Avoid brittleness if token order changes. Assert both tokens are present.

-            expect(poweredByLink).toHaveAttribute('rel', 'noopener noreferrer');
+            const rel = poweredByLink.getAttribute('rel') || '';
+            expect(rel).toContain('noopener');
+            expect(rel).toContain('noreferrer');

357-357: Prefer findByRole for async rendering in iframe.

Using findByRole reduces flakiness if the link renders slightly after the iframe is ready.

-            const poweredByLink = within(popupFrame.contentDocument).getByRole('link', {name: /powered by ghost/i});
+            const poweredByLink = await within(popupFrame.contentDocument).findByRole('link', {name: /powered by ghost/i});
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f2844e3 and f0906e2.

📒 Files selected for processing (1)
  • apps/portal/src/tests/portal-links.test.js (1 hunks)
🔇 Additional comments (1)
apps/portal/src/tests/portal-links.test.js (1)

347-355: Good coverage of the PoweredBy link semantics.

Asserting presence, href, target, and rel on the link is solid and aligns with the fix.

Comment on lines +357 to +364
const poweredByLink = within(popupFrame.contentDocument).getByRole('link', {name: /powered by ghost/i});
expect(poweredByLink).toBeInTheDocument();
expect(poweredByLink).toHaveAttribute('href', 'https://ghost.org');
expect(poweredByLink).toHaveAttribute('target', '_blank');
expect(poweredByLink).toHaveAttribute('rel', 'noopener noreferrer');
// Verify no onClick handler exists
expect(poweredByLink.onclick).toBeNull();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Replace brittle onclick check with an interaction-based assertion (spy on iframe window.open).

element.onclick is null even when a framework attaches an onClick via addEventListener. This check won’t catch regressions. Instead, spy on popupFrame.contentWindow.open, click the link, and assert it wasn’t called.

-            const poweredByLink = within(popupFrame.contentDocument).getByRole('link', {name: /powered by ghost/i});
+            const poweredByLink = within(popupFrame.contentDocument).getByRole('link', {name: /powered by ghost/i});
             expect(poweredByLink).toBeInTheDocument();
             expect(poweredByLink).toHaveAttribute('href', 'https://ghost.org');
             expect(poweredByLink).toHaveAttribute('target', '_blank');
             expect(poweredByLink).toHaveAttribute('rel', 'noopener noreferrer');
-            // Verify no onClick handler exists
-            expect(poweredByLink.onclick).toBeNull();
+            // Clicking the link should not invoke script-driven window.open (prevents "two tabs" regression)
+            const openSpy = jest.spyOn(popupFrame.contentWindow, 'open').mockImplementation(() => null);
+            fireEvent.click(poweredByLink);
+            expect(openSpy).not.toHaveBeenCalled();
📝 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.

Suggested change
const poweredByLink = within(popupFrame.contentDocument).getByRole('link', {name: /powered by ghost/i});
expect(poweredByLink).toBeInTheDocument();
expect(poweredByLink).toHaveAttribute('href', 'https://ghost.org');
expect(poweredByLink).toHaveAttribute('target', '_blank');
expect(poweredByLink).toHaveAttribute('rel', 'noopener noreferrer');
// Verify no onClick handler exists
expect(poweredByLink.onclick).toBeNull();
});
const poweredByLink = within(popupFrame.contentDocument).getByRole('link', {name: /powered by ghost/i});
expect(poweredByLink).toBeInTheDocument();
expect(poweredByLink).toHaveAttribute('href', 'https://ghost.org');
expect(poweredByLink).toHaveAttribute('target', '_blank');
expect(poweredByLink).toHaveAttribute('rel', 'noopener noreferrer');
// Clicking the link should not invoke script-driven window.open (prevents "two tabs" regression)
const openSpy = jest.spyOn(popupFrame.contentWindow, 'open').mockImplementation(() => null);
fireEvent.click(poweredByLink);
expect(openSpy).not.toHaveBeenCalled();
🤖 Prompt for AI Agents
In apps/portal/src/tests/portal-links.test.js around lines 357 to 364, replace
the brittle check of poweredByLink.onclick being null with an interaction-based
assertion: create a spy/mock on popupFrame.contentWindow.open (or
jest.spyOn(popupFrame.contentWindow, 'open')), simulate a user click on the
poweredByLink (use userEvent.click or element.click()), and assert that
contentWindow.open was not called; remove the onclick assertion and keep the
href/target/rel attribute expectations so the test verifies behavior rather than
presence of an onclick property.

@ErisDS ErisDS added the community [triage] Community features and bugs label Sep 17, 2025
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants