-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Migrate product pages to Inertia #3300
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
base: main
Are you sure you want to change the base?
Conversation
| before_action :fetch_product_and_enforce_access, only: %i[update publish unpublish release_preorder update_sections] | ||
|
|
||
| layout "inertia", only: [:index, :new, :cart_items_count] | ||
| layout "inertia", only: [:index, :new, :cart_items_count, :show] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Product pages are now Inertia pages, so they use the same inertia layout as other Inertia actions (index, new, cart_items_count). That way /l/:id gets the inertia layout and the base pack loads correctly. Without :show, product pages would use the default application layout and the Inertia app wouldn’t mount.
| format.html do | ||
| product_page_props = @product_props.merge(hide_layouts: true) | ||
| if params[:layout] == "profile" | ||
| render inertia: "Links/Profile", props: product_page_props.merge({ | ||
| creator_profile: ProfilePresenter.new(pundit_user:, seller: @product.user).creator_profile | ||
| }) | ||
| elsif params[:layout] == Product::Layout::DISCOVER | ||
| render inertia: "Links/Discover", props: product_page_props.merge(@discover_props) | ||
| elsif params[:embed] || params[:overlay] | ||
| render inertia: "Links/Iframe", props: product_page_props | ||
| else | ||
| render inertia: "Links/Show", props: product_page_props |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We now render a different Inertia page per layout (Links/Show, Profile, Discover, Iframe) instead of ERB + React-on-Rails. We merge hide_layouts: true into product props so the shared Layout can hide the Nav
| hide_layouts?: boolean; | ||
| }; | ||
|
|
||
| export default function Layout({ children }: { children: React.ReactNode }) { | ||
| const { flash, logged_in_user, current_seller } = usePage<PageProps>().props; | ||
| const { flash, logged_in_user, current_seller, hide_layouts } = usePage<PageProps>().props; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We read hide_layouts from page props and only render the Nav when logged_in_user && !hide_layouts. Product pages pass hide_layouts: true, so they get the same Layout (and providers) but no sidebar.
| </div> | ||
| <%= javascript_include_tag "application" %> | ||
| <%= load_pack("base") unless @hide_layouts %> | ||
| <%= load_pack("base") if inertia_rendering? || !@hide_layouts %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We changed to load_pack("base") if inertia_rendering? || !@hide_layouts so the base pack (Inertia app) loads on product pages too. On main, base wasn’t loaded when @hide_layouts was true; now it must be when the response is Inertia, or the product page wouldn’t hydrate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ProductPage, ProfileProductPage, DiscoverProductPage, and ProductIframePage are removed; product pages are now Inertia (Links/Show, etc.). ProfileCoffeePage stays for the coffee profile React-on-Rails page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Links/Show, Profile, Discover, and Iframe are thin Inertia pages that delegate to the existing Product/Profile/Discover/Iframe layout components. They use the default Inertia layout (with hide_layouts hiding the Nav), not layout = false.
sahitya-chandra
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self review
|
@Pradumn27 _a sir, can you give an initial review of this pr? |
Issue: #3061 (Parent: #3028)
closes: #3061
Description
Migrates product pages from React on Rails / ERB to Inertia by rendering a different Inertia page per layout
Problem
app/views/links/show.html.erbwith conditionalreact_componentcalls (ProductPage, ProfileProductPage, DiscoverProductPage, ProductIframePage) based onparams[:layout],params[:embed], andparams[:overlay].Solution
LinksController#shownow uses Inertia for all HTML responses:Links/Show(default product page)Links/Profilewhenparams[:layout] == "profile"Links/Discoverwhenparams[:layout] == "discover"Links/Iframewhenparams[:embed]orparams[:overlay]:showtolayout "inertia", only: [...].hide_layouts: truein product page props and extend the shared Inertia layout to respecthide_layoutsso the dashboard Nav is not rendered on product pages.app/javascript/pages/Links/(Show, Profile, Discover, Iframe) that use the existing Product/Profile/Discover/Iframe layout components.app/views/links/show.html.erband the React-on-Rails product page components fromapp/javascript/packs/product.tsandapp/javascript/ssr.ts.inertia_rendering? || !@hide_layoutsso product Inertia pages still load the app.spec/controllers/links_controller_spec.rbfor the new Inertia behavior.Before/After
Before: Product page was rendered by ERB and React on Rails (conditional
react_componentfor ProductPage, ProfileProductPage, DiscoverProductPage, ProductIframePage).Screencast.from.2026-02-02.03-04-39.webm
After: Product page is rendered by Inertia (Links/Show, Links/Profile, Links/Discover, Links/Iframe) with the same UI;
Screencast.from.2026-02-02.03-09-57.webm
Test Results
bundle exec rspec spec/controllers/links_controller_spec.rb:3210 spec/controllers/links_controller_spec.rb:3217 spec/controllers/links_controller_spec.rb:3224 spec/controllers/links_controller_spec.rb:3231 spec/controllers/links_controller_spec.rb:3238Checklist
AI Disclosure