Skip to content

fix: ensure turbo stream names are generated based on decorated object#961

Merged
Alexander-Senko merged 2 commits into
drapergem:masterfrom
markokajzer:master
Feb 14, 2026
Merged

fix: ensure turbo stream names are generated based on decorated object#961
Alexander-Senko merged 2 commits into
drapergem:masterfrom
markokajzer:master

Conversation

@markokajzer
Copy link
Copy Markdown
Contributor

@markokajzer markokajzer commented Feb 13, 2026

Description

closes #960 via suggested fix.

#928 introduced a subtle issue where turbo stream names are generated based on the decorated object, not the actual object as before.

Copy link
Copy Markdown
Collaborator

@Alexander-Senko Alexander-Senko left a comment

Choose a reason for hiding this comment

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

The goal is not just to fix Turbo's behavior in this particular case. We want GIDs to point to records every time they are passed between server and client sides. I hope #to_param is meant for that.

Comment thread lib/draper/compatibility/global_id.rb Outdated
include ::GlobalID::Identification

# NOTE: Ensure turbo stream names are generated based on decorated object
delegate :to_gid_param, to: :object
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
delegate :to_gid_param, to: :object
delegate :to_gid_param, :to_sgid_param, to: :object

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i totally missed this from your suggestion in the issue discussion... mb!

Comment thread .gitignore Outdated
@markokajzer
Copy link
Copy Markdown
Contributor Author

markokajzer commented Feb 13, 2026

added delegation of to_sgid_param as well, sorry I missed that.

I'm not sure I fully understand your comment though as im not familiar with GlobalID all too much, so let me know if there are any other things we need to take care! 🙏

Copy link
Copy Markdown
Collaborator

@Alexander-Senko Alexander-Senko left a comment

Choose a reason for hiding this comment

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

The last thing is to figure out why SGIDs fail to match half of the time.

@markokajzer
Copy link
Copy Markdown
Contributor Author

markokajzer commented Feb 14, 2026

it seems like there's a timing related flake. A Signed Global ID seems to include an expiration timestamp in the ms range. Example:

{"_rails":{"data":"gid://dummy/Post/1","exp":"2026-03-14T14:20:07.394Z","pur":"default"}}

To get around that, I included ActiveSupport::Testing::TimeHelpers for this spec (since rails is loaded), and used freeze_time around it. In the run the expiration now ends in .000Z for both generations.

Let me know if that works 👍

Copy link
Copy Markdown
Collaborator

@Alexander-Senko Alexander-Senko left a comment

Choose a reason for hiding this comment

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

@markokajzer, thanks for your contribution, great job!

@seanlinsley, could we release a patch?

@Alexander-Senko Alexander-Senko merged commit 0ef01f9 into drapergem:master Feb 14, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent turbo stream names for decorated vs non-decorated objects

2 participants