Skip to content

feat: Adds support for providing default URL parameters via the frontend #75

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

owenconti
Copy link

@owenconti owenconti commented Aug 1, 2025

This should resolve #49

This PR adds support for providing default URL values during runtime via the frontend. This works by providing methods within the wayfinder.ts that user-land code can call to set (or add individual) default parameters. These parameters are stored in a global Wayfinder window object.

When generating the URL for a controller, we merge in any set default parameters, making sure that we don't override any keys already set during the calling of the url method.

Note: in theory we don't need to use a window object here, but when running the test suite, it seems like I was getting different instances of the wayfinder.ts file, the default parameters that were set were getting lost.

Usage

Here's how I have it set up in our app. The benefit here is it is up to the user to decide where and when to apply the defaults:

  setup({ el, App, props }) {
    const root = createRoot(el);

    setDefaultParameters({
      workspace: props.initialPage.props.workspace.slug
    });

    root.render(<App {...props} />);
  },

One thing I have not figured out with this approach is non-optional parameters that do not have a default set via the URL facade on the backend. Wayfinder doesn't know that domain parameter is being set as a default and will be applied/set during the url() call:

Screenshot 2025-08-01 at 8 42 53 AM

@owenconti owenconti force-pushed the default-parameters-frontend-support branch from 9a3deb4 to 722e0fc Compare August 1, 2025 14:51
@owenconti owenconti force-pushed the default-parameters-frontend-support branch from 722e0fc to 5ed96ae Compare August 1, 2025 14:59
@bdweix
Copy link

bdweix commented Aug 12, 2025

Nice work @owenconti - excited for this one!

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.

Dealing with subdomains
2 participants