Skip to content

Pass siteSlug as component prop instead of using router instances #103502

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

Merged
merged 1 commit into from
May 19, 2025

Conversation

taipeicoder
Copy link
Contributor

@taipeicoder taipeicoder commented May 16, 2025

Proposed Changes

This PR passes siteSlug as component prop from the router, instead of explicitly using path-specific route instances within components. This change allows the components to decouple from route instances, making them reusable in the case of backporting where another router instance is used.

Why are these changes being made?

Decouple components from route instances.

Testing Instructions

  • Head to /v2/sites/:site/settings/
  • Navigate to settings such as site visibility and gift subscription, and ensure that they still work as intended.

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
    • For UI changes, have we tested the change in various languages (for example, ES, PT, FR, or DE)? The length of text and words vary significantly between languages.
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-aUh-p2)?

@taipeicoder taipeicoder self-assigned this May 16, 2025
@matticbot
Copy link
Contributor

matticbot commented May 16, 2025

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

App Entrypoints (~29 bytes added 📈 [gzipped])

name                    parsed_size           gzip_size
entry-dashboard-dotcom       +124 B  (+0.0%)      +14 B  (+0.0%)
entry-dashboard-a4a          +124 B  (+0.0%)      +15 B  (+0.0%)

Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

import PageLayout from '../../components/page-layout';
import SettingsPageHeader from '../settings-page-header';
import { LaunchForm } from './launch-form';
import { PrivacyForm } from './privacy-form';

export default function SiteVisibilitySettings() {
const { siteSlug } = siteSettingsSiteVisibilityRoute.useParams();
const { siteSlug } = useParams( { strict: false } );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

strict: false is needed otherwise useParams throws an error saying that the param from is needed. Adding the from defeats the purpose of this PR since it's the route path.

@taipeicoder taipeicoder marked this pull request as ready for review May 16, 2025 15:37
@taipeicoder taipeicoder requested review from youknowriad and a team as code owners May 16, 2025 15:37
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label May 16, 2025
Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

This makes sense to me. Thanks

@youknowriad
Copy link
Contributor

So just for clarify, we lose the "types" here right? Doesn't seem like a big problem right now but we might want to restore "from" later if reusability of these components is not needed anymore.

The other possibility is to actually reuse UI components, the "route" component become just wrappers.

@taipeicoder taipeicoder changed the title Use TanStack Router useParams to get route params Pass siteSlug as component prop instead of using router instances May 17, 2025
@taipeicoder
Copy link
Contributor Author

@youknowriad I ended up passing siteSlug as a props component from the router instead of using router instances. Let me know if there are concerns with this approach, thanks.

@matticbot
Copy link
Contributor

This PR modifies the release build for the following Calypso Apps:

For info about this notification, see here: PCYsg-OT6-p2

  • blaze-dashboard
  • command-palette-wp-admin
  • help-center
  • notifications
  • odyssey-stats
  • wpcom-block-editor

To test WordPress.com changes, run install-plugin.sh $pluginSlug update/use-params-with-strict-false on your sandbox.

@youknowriad
Copy link
Contributor

It works for me :)

@taipeicoder taipeicoder force-pushed the update/use-params-with-strict-false branch from 24df7d2 to f67a920 Compare May 17, 2025 13:28
@taipeicoder taipeicoder merged commit 2f565cf into trunk May 19, 2025
13 of 14 checks passed
@taipeicoder taipeicoder deleted the update/use-params-with-strict-false branch May 19, 2025 01:58
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label May 19, 2025
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.

3 participants