Skip to content

Commit

Permalink
use template instead of meta for content
Browse files Browse the repository at this point in the history
  • Loading branch information
JensRavens committed Jan 16, 2025
1 parent c8823af commit bce687a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions app/frontend/sprinkles/reaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ export class Reaction {
const rootElement = document.getElementById('root');
if (!rootElement) throw new Error('Root element not found');
const metaJson = (
document.querySelector('meta[name="reaction-data"]') as HTMLMetaElement
).content;
document.querySelector(
'template[id="reaction-data"]'
) as HTMLTemplateElement
).content.textContent;
const data = metaJson ? JSON.parse(decodeURIComponent(metaJson)) : {};
const meta = new Meta(data);
meta.path = window.location.pathname + window.location.search;
Expand Down
2 changes: 1 addition & 1 deletion lib/reaction/tsx_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def render(path, assigns, context)
id = Pathname.new(path).relative_path_from(Rails.root.join("app", "views")).to_s.sub(".tsx", "")
response = Response.new(component: id, context:)
<<~HTML
<meta name="reaction-data" content="#{ERB::Util.url_encode(response.to_s)}" />
<div id="root"></div>
<template id="reaction-data" style="display: none;">#{ERB::Util.url_encode(response.to_s)}</template>
HTML
end
end
Expand Down

0 comments on commit bce687a

Please sign in to comment.