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

using counter-increment inside of @page causes the script to break #180

Open
bakkot opened this issue Jan 9, 2024 · 3 comments
Open

using counter-increment inside of @page causes the script to break #180

bakkot opened this issue Jan 9, 2024 · 3 comments

Comments

@bakkot
Copy link

bakkot commented Jan 9, 2024

A minimal repro:

<!doctype html>
<script src="https://unpkg.com/pagedjs/dist/paged.polyfill.js"></script>
<style>
body {
  counter-reset: xyz;
}
@page {
  counter-increment: xyz;
}
</style>
content

This throws TypeError: Cannot read properties of null (reading 'type').

From the debugger, the problem appears to be that this line assumes rule.ruleNode.prelude is never null. Here it is. The problematic ruleNode is the {type: 'Atrule', name: 'page' /*etc*/} node.

@stueybrock
Copy link

What's the intended use case here, page numbering? Could you provide a bit more context?

@bakkot
Copy link
Author

bakkot commented Jan 25, 2024

Mostly I was following this writeup about laying out a book with CSS, and he mentions

If your task involves printing dynamic content (e.g. JS-based charting), you can do it with paged.js and preview the results in a nice browser view… or so I’m told. When I tried, paged.js threw an exception trying to read a property off of null while walking the AST. Unlinking my stylesheet fixed it, but that’s hardly a solution. Thankfully I’m just writing an addendum to a blog post, so I can shrug and walk away.

I was curious what the cause was, so I isolated this minimal repro from his code. He was indeed using the counters for page numbers.

@julientaq
Copy link
Collaborator

if you set a counter-reset on the body, it will override any counter-reset paged.js will add.

i believe that @fchasen is aware of this.

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

3 participants