Skip to content
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

[Craft 5] Error "..registerScript(): Argument #1 ($script) must be of type string" in production #407

Open
naboo opened this issue Dec 3, 2024 · 3 comments

Comments

@naboo
Copy link

naboo commented Dec 3, 2024

Description

When pushing code to PRODUCTION this error happens whenever I try to display a Map:

craft\web\View::registerScript(): Argument #1 ($script) must be of type string, null given, called in /home/craft/www.domain.com/vendor/craftcms/cms/src/services/TemplateCaches.php on line 323

The code works as it should in DEV.

If I just switch my environment to "production" in my dev area the same error appears.

Additional info

  • Craft version: Craft CMS 5.5.4
  • Maps version: 5.0.4
  • PHP version: 8.2
@naboo
Copy link
Author

naboo commented Dec 4, 2024

So the issue is with Crafts cache tag. If you wrap code within the cache tag (and not the entire full page) the scripts injected by the tag will not be registered (since Craft is outputting cached content and not injecting the embeded map field).

Is there a workaround for this? Like injecting the script code inline in the HTML or similar?

@alexjcollins
Copy link
Member

Thanks for bringing this up, @naboo. We're going to discuss it internally and come back to you.

@naboo
Copy link
Author

naboo commented Dec 4, 2024

For now I've wrapped all my map fields in iframes with a custom route so a blank un-cached page that just displayes the map. If anyone runs in the same issue. Like this:

<iframe src="{{ url('template/goes-here' ~ entry.id) }}" style="width: 100%; height: 600px;" scrolling="no"></iframe>

<html>
<head>{{ head() }}</head>
<body>
	{{ beginBody() }}
{% set entry = craft.entries.section('section').id(craft.app.request.segments|last).one() %}

{{ entry.mapField.embed({id: 'map', markers: [{label: entry.title}]})|attr({
    style: 'width: 100%; height: 600px;',
}) }}

{{ endBody() }}
</body>
</html>

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

No branches or pull requests

2 participants