Skip to content

Clarify render_preview + with_request_url behavior after 4.21.0 #2776

Closed

Description

@yasaichi

After upgrading from ViewComponent 4.19.0 to 4.21.0, we observed a change in URL generation when combining render_preview with with_request_url. For a component calling url_for(bar: 'baz'), rendering its preview inside with_request_url('/foo') now generates:

/rails/view_components/routing_probe_component/default?bar=baz

vc_test_request.path still returns /foo after rendering, even though the generated link points to the preview route. Replacing only render_preview with its implementation from v4.19.0 restores the previous result:

/foo?bar=baz

This appears to follow #2763, which creates an isolated preview request and replaces its controller, action, and preview path parameters before processing the action. The added test_render_preview_preserves_the_original_request_parameters covers this combination, but verifies that the original request remains unchanged rather than checking URL generation inside the preview. The documented with_request_url examples use render_inline.

Is this change in routing context intentional? Should with_request_url affect request-dependent URL generation inside render_preview? If the current behavior is intended, what is the recommended way to test request-dependent links using previews? Clarifying this interaction in the documentation would also help.

Activity

  1. joelhawksley commented on Nov 4, 2026

    @joelhawksley
    Member

    Thanks for the report. This was not an intentional change. I've fixed it in #2777.

  2. yasaichi commented on Nov 5, 2026

    @yasaichi
    Author

    Thanks for the quick fix, @joelhawksley! I appreciate the regression tests and documentation too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions